0
ユーザが入力フィールドに値を入力したときに、オブジェクト内のデータをフィルタリングするJqueryには次のフィルタがありますが、これはうまくいきますが、ユーザ入力はオブジェクト内の任意の売り手名と一致します。国の場合私は(val.country.search(regex) != -1)
を持っていますが、キー名がないので売り手の名前をどのように追加しますか?オブジェクト内の値によるフィルタ
オブジェクト:
{
"28": {
"name": "Alex",
"country": "Spain",
"antiquity": "new client",
"amount": "2690.58 USD",
"sellers": {
"Bob": "2690.58 USD",
"Harold": "2690.58 USD"
}
},
"29": {
"name": "Bill",
"country": "UK",
"antiquity": "new client",
"amount": "2690.58 USD",
"sellers": {
"Support": "2690.58 USD",
"admin": "2690.58 USD"
}
},
"30": {
"name": "Jeff",
"country": "USA",
"antiquity": "new client",
"amount": "2690.58 USD",
"sellers": {
"tom": "2690.58 USD",
"harry": "2690.58 USD"
}
}
}
はJQuery:
var regex = new RegExp(searchField, "i");
var searchField = $('#search').val();
var regex = new RegExp(searchField, "i");
var output;
var count = 1;
$.each(response, function(key, val){
if ((val.name.search(regex) != -1) || (val.country.search(regex) != -1) || (val.antiquity.search(regex) != -1)){
....
}
});