With Reference of below links:
https://stackoverflow.com/posts/4391119/revisions
Filter JSON Data with multiple record IDs in jQuery
What if there is a Hierarchical Data in JSON.. I've tried making modification in that filterStore function.. but not being succeeded. Can you help me with that??
Current filterStore is like this:
var filter = {
"brand_id": [1,2,3],
"productname": new RegExp('(.*?)', 'gi'),
"price": new RegExp('.*?', 'gi')
};
function filterStore(dataStore, filter) {
return $(dataStore).filter(function(index, item) {
for( var i in filter ) {
if(filter[i] instanceof Array){
if($.inArray(parseInt(item[i],10),filter[i]) == -1)
return null;
else
continue;
}
if( ! item[i].toString().match( filter[i] ) ) return null;
}
return item;
});
}
but json response is something like this:
[
{
"brandInfo": {
"brand": "Lg",
"productname": "Microwave",
},
"prodInfo": {
"size": "1.5 ltr",
"price": 200,
"color": "black"
},
"Category": "Electronic",
"shop": "Walmart"
}
{
"brandInfo": {
"brand": "Samsung",
"productname": "Microwave",
},
"prodInfo": {
"size": "1.5 ltr",
"price": 250,
"color": "Ivory"
},
"Category": "Electronic",
"shop": "Walmart"
}
{
"brandInfo": {
"brand": "Toshiba",
"productname": "Microwave",
},
"prodInfo": {
"size": "1.6 ltr",
"price": 310,
"color": "Silver"
},
"Category": "Electronic",
"shop": "Walmart"
}
{
"brandInfo": {
"brand": "Hitachi",
"productname": "Microwave",
},
"prodInfo": {
"size": "1.5 ltr",
"price": 280,
"color": "black"
},
"Category": "Electronic",
"shop": "Walmart"
}
]
Joy, Can you help me set filters for hierarchical data like this?? new function filterStore?