jeudi 23 juin 2016

Ember js - Filter list with nested arrays in JSON/Model

I have been trying to filter a list using the below code.

controller.js

return this.get('model').filter(function(item, index, enumerable){
    for(var i=0;i<item.options.length;i++){
      return item.options[i].key == "one"
    }
  });

I have a nested JSON and want to filter on basis of some nested properties. Below is my JSON and also a blob link to it.

JSON - http://ift.tt/28Qk7tZ

enter image description here

So, the need is to filter this object which has 5 child objects, on the basis of "key" property, as shown in screenshot. I have no idea if that is actually achievable using the above filter or not.

The above code will return true as soon as it finds first "one". But i want to loop through all objects in "options" array and filter based on key, as there might be more matching "key" and hence want to return true for all those matching one's.




Aucun commentaire:

Enregistrer un commentaire