So I really would like to make a duplicate out of my previous failed question because I wasn't really able to explain myself properly and thus didn't get the answer (and haven't really solved my issue).
There is the JSON:
[
{
"id": 2,
"name": "Google",
"country": "Sweden"
},
{
"id": 3,
"name": "Google",
"country": "USA"
},
{
"id": 9,
"name": "Google",
"country": "Ukraine"
},
{
"id": 10,
"name": "Bing",
"country": "Sweden"
}
]
What I failed to do previously I guess is to post what I have so far and explain better what I need. This is what I have right now:
$scope.loadSearchEngines = function ($query) {
return $http.get('search-engines.json', {cache: true}).then(function (response) {
var tags = response.data;
return tags.filter(function (tag) {
return tag.name.toLowerCase().indexOf($query.toLowerCase()) != -1;
});
});
};
This filter restricts me to search through only the name property, while ideally I would like to search through any property (or well, all the properties, rather) and I'd like the filter to work with an array of parameters so that each word would separately look through each property in the object and find a match.
In the previous post a person posted a for loop for it, but that is exactly the kind of unintuitive thing I want to avoid. I know what I want the result to be but I just can't think of an approach (lodash/underscore seemingly almost does something like this, but I think there is something missing from somewhere or I am really bad at understanding the docs).
Examples:
In case I write "google sweden", it will only show the 1 result, if I write "sweden", it would show the one from google and the one from bing. In case I write "in", it should show "bINg" and google "ukraINe" I guess.
This seemed like a much less of a hassle at first but I can't really wrap my head around this using a filter. I really don't have any ideas to post because they have been embarrassingly bad and this is a really grey area for me.
Aucun commentaire:
Enregistrer un commentaire