There is such an object:

data: Object attachments: Object animations: Array[0] audios: Array[4] 0: Object artist: "Perturbator" duration: 262 title: "Humans Are Such Easy Prey" 1: Object artist: "Johann Sebastian Bach" duration: 505 title: "Toccata and Fugue in D minor, BWV 565" 2: Object artist: "Sabaton - Primo Victoria" duration: 272 title: "Primo Victoria" 3: Object artist: "Johny Cash" duration: 218 title: "Hurt.. I hurt myself today" 

I'm trying to make filtering possible. For example, if the word "Victoria" is present in one of the properties, then the entire data object falls into the filtering results, if not, it does not.

I'm trying to filter like this:

 console.log($filter('filter')(content, { attachments: self.textSearch })); 

Like this:

 console.log($filter('filter')(content, { attachments: { audios: self.textSearch } })); 

And so:

 console.log($filter('filter')(content, { attachments: { audios: { artist: self.textSearch, title: self.textSearch } } })); 

But I always get an empty result. How to implement filtering correctly in this case?

  • 2
    Give an example of an object in the form of json. And what is the content ? Well, since you want to fail, because you need to specify the full path to the property being checked, and you have it in the internal array - write your comparator function - Grundy

1 answer 1

Following the advice of @Grundy, I wrote my comparator function:

 content = $filter('filter')(content, function(post) { var text = post.text.toLowerCase(); var search = self.textSearch.toLowerCase(); if (text.indexOf(search) != -1) { return true; } else { for (var i = 0; i < post.attachments.audios.length; i++) { var track = post.attachments.audios[i]; var text = (track.artist + track.title).toLowerCase(); if (text.indexOf(search) != -1) { return true; } } } return false; }); 

P.S. By the way, if you see any bottlenecks that can be accelerated, leave a comment.