2
多個記錄ID下面鏈接的參考:篩選分級JSON數據與jQuery的
https://stackoverflow.com/posts/4391119/revisions
Filter JSON Data with multiple record IDs in jQuery
如果有什麼是JSON一個層次數據。我已經試過做修改在那個filterStore函數中,但沒有成功。你能幫助我嗎?
當前filterStore是這樣的:
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;
});
}
但JSON響應是這樣的:
[
{
"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"
}
]
喜悅,你能不能幫我要像這樣的分層數據集中的過濾器?新功能filterStore?
使用jLinq ..使數據對象成爲一個夢 – ppumkin