javascript - Backbone where method for item object -


below sample json data

"items": [{                 "id": "18",                 "attributes": [{                     "identifier": "style",                     "value": "peacock"                 }, {                     "identifier": "size",                     "value": "l"                 }]             },             {                 "id": "300438",                 "attributes": [{                     "identifier": "style",                     "value": "peacock"                 }, {                     "identifier": "size",                     "value": "m"                 }]             }] 

i need item id style = peacock , size = l. how can using backbone?

i have made collection like

var itemscollection = new iea.collection(itemsdata) 

this has items.

underscore.js not support filtering of nested objects ,you can use combination between filter , functions

filtereditems = itemscollection.filter(function(item) {   return _.where(item.get("attributes"), {       "identifier": "style",       "value": "peacock"     }).length > 0 &&     _.where(item.get("attributes"), {       "identifier": "size",       "value": "m"     }).length > 0; }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -