Click here to Skip to main content
15,892,298 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: What is J Query in Javascript Pin
Wishe199129-Sep-19 23:22
Wishe199129-Sep-19 23:22 
AnswerRe: What is J Query in Javascript Pin
Shraddha_Patel13-Oct-19 23:47
Shraddha_Patel13-Oct-19 23:47 
QuestionSorting an array in typescript, based on a search query Pin
jkirkerx6-Sep-19 7:31
professionaljkirkerx6-Sep-19 7:31 
AnswerRe: Sorting an array in typescript, based on a search query Pin
jkirkerx18-Sep-19 13:37
professionaljkirkerx18-Sep-19 13:37 
GeneralRe: Sorting an array in typescript, based on a search query Pin
Nathan Minier19-Sep-19 1:37
professionalNathan Minier19-Sep-19 1:37 
GeneralRe: Sorting an array in typescript, based on a search query Pin
jkirkerx19-Sep-19 7:18
professionaljkirkerx19-Sep-19 7:18 
GeneralRe: Sorting an array in typescript, based on a search query Pin
Nathan Minier19-Sep-19 7:24
professionalNathan Minier19-Sep-19 7:24 
GeneralRe: Sorting an array in typescript, based on a search query Pin
jkirkerx19-Sep-19 9:16
professionaljkirkerx19-Sep-19 9:16 
I opted for this. The foundIn forced me to create another class for search Results that wasn't compatible with what I have already. But your example works great, and I did rewrite it from scratch.
export interface SubCategorySearchResults {
  subCategory: SubCategories;
  foundIn: string;
}
export class SubCategories {
  Id: string;
  Name: string;
  Description: string;
  CreatedBy: string;
  CreatedOn: Date;
  UpdatedOn: Date;
  Selected: boolean;
}

// And produced this JSON

[{"subCategory":{"Id":"5d7fd71ef9a41e064ce3cbd9","Name":"Super Thick","Description":"Non moving gel","CreatedBy":"admin","CreatedOn":"2019-09-16T18:40:30.887Z","UpdatedOn":"2019-09-16T18:40:30.859Z","Selected":false},"foundIn":"Name"},{"subCategory":{"Id":"5d7fd63bf9a41e064ce3cbd8","Name":"Thick","Description":"Very Slow Moving Gels","CreatedBy":"admin","CreatedOn":"2019-09-16T18:36:43.762Z","UpdatedOn":"2019-09-16T18:36:43.718Z","Selected":false},"foundIn":"Name"},{"subCategory":{"Id":"5d7fd418f9a41e064ce3cbd6","Name":"Thin ","Description":"Fast moving","CreatedBy":"admin","CreatedOn":"2019-09-16T18:27:36.675Z","UpdatedOn":"2019-09-16T18:27:36.645Z","Selected":false},"foundIn":"Name"}]{

What I wrote, I went back to the const because it self creates a model and just rewrote my this.model.SubCategories.
It's a work in progress. Thanks!
searchSubCategories2(): void {

  const query = this.subCategoriesForm.controls["searchQuery"].value.toLowerCase();
  if (query) {
    const results = this.model.SubCategories.map(sub => {
      if (sub.Name.toLowerCase().includes(query)) {
        return { subCategory: sub, foundIn: "Name" };
      }
      if (sub.Description.toLowerCase().includes(query)) {
        return { subCategory: sub, foundIn: "Description" };
      }
    });

    if (results) {
      results.sort((a, b) => {
        if (a.foundIn !== b.foundIn) {
          if (a.foundIn === "Name") { return -1; }
          if (b.foundIn === "Name") { return 1; }
        }
        return 0;
      });

      this.model.SubCategories = [];
      results.forEach(result => {
        this.model.SubCategories.push(result.subCategory);
      });

      console.log(JSON.stringify(results));
      console.log(JSON.stringify(this.model.SubCategories));
    }
  }
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com

GeneralRe: Sorting an array in typescript, based on a search query Pin
Wishe199129-Sep-19 23:23
Wishe199129-Sep-19 23:23 
QuestionJavascript object comparison Pin
Anandkumar Prajapati28-Aug-19 19:24
professionalAnandkumar Prajapati28-Aug-19 19:24 
AnswerRe: Javascript object comparison Pin
Richard MacCutchan28-Aug-19 21:32
mveRichard MacCutchan28-Aug-19 21:32 
GeneralRe: Javascript object comparison Pin
A_Griffin20-Sep-19 11:13
A_Griffin20-Sep-19 11:13 
GeneralRe: Javascript object comparison Pin
Richard MacCutchan20-Sep-19 20:47
mveRichard MacCutchan20-Sep-19 20:47 
QuestionCopying Text from Web Message Box/pop-Up Window Pin
Member 1456795025-Aug-19 2:07
Member 1456795025-Aug-19 2:07 
AnswerRe: Copying Text from Web Message Box/pop-Up Window Pin
Richard MacCutchan25-Aug-19 4:25
mveRichard MacCutchan25-Aug-19 4:25 
QuestionHow do I a value from one function and pass it through to another for use Pin
Member 1028754813-Aug-19 11:13
Member 1028754813-Aug-19 11:13 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
Richard MacCutchan13-Aug-19 21:33
mveRichard MacCutchan13-Aug-19 21:33 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
rinave19-Aug-19 15:58
rinave19-Aug-19 15:58 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:36
professionalZurdoDev21-Aug-19 5:36 
GeneralRe: How do I a value from one function and pass it through to another for use Pin
Richard Deeming21-Aug-19 8:26
mveRichard Deeming21-Aug-19 8:26 
AnswerRe: How do I a value from one function and pass it through to another for use Pin
ZurdoDev21-Aug-19 5:35
professionalZurdoDev21-Aug-19 5:35 
QuestionComparison's in JavaScript Pin
BobInNJ7-Aug-19 10:57
BobInNJ7-Aug-19 10:57 
AnswerRe: Comparison's in JavaScript Pin
ZurdoDev7-Aug-19 11:10
professionalZurdoDev7-Aug-19 11:10 
AnswerRe: Comparison's in JavaScript Pin
Anandkumar Prajapati19-Sep-19 18:55
professionalAnandkumar Prajapati19-Sep-19 18:55 
QuestionDelete consumer Pin
Member 1453057115-Jul-19 0:09
Member 1453057115-Jul-19 0:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.