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
Post a Comment