Tag: grep

具有多个搜索标准的Jquery grep或map对象数组

我在JSON中有一个价目表: {Products: [{AdminID: 137, ProduktID: “07.1434”, itemName: “Repaplast”, itemColor: “0000, 5030”, MalKode: “1-3”, …}{AdminID: 6, ProduktID: “07.1436”, itemName: “Repaplast grå”, itemColor: “0070”, MalKode: “1-3”, …}{AdminID: 146, ProduktID: “90.0905”, itemName: “Mixer Gun”, itemColor: null, MalKode: “”, …}{AdminID: 89, ProduktID: “02.0135”, itemName: “Repaplast Primer NEW FORMULA”, itemColor: “”, MalKode: “5-3”, …}]} 该列表大约有400个产品。 假设我想限制列表,只显示基于ProduktID字段的特定产品(这是唯一的)。 假设我有一个产品清单: 07.1438,01,1340,05,04531,02.0135 逗号是分隔符。 我如何基于这些输入.grep或.map对象数组? […]

使用带有通配符的jquery grep搜索对象数组

我正在使用jquery grep搜索一个对象数组,并希望在搜索中包含通配符。 例如,我有一个数组如下: courses = [ {code: ‘ENCH3TH’, otherFields: otherStuff}, {code: ‘ENCH3THHS1’, otherFields: otherStuff}, {code: ‘ENCH3TH2’, otherFields: otherStuff}, {code: ‘ENCH4RT’, otherFields: otherStuff}, {code: ‘ENCH4MT’, otherFields: otherStuff}] 我想用ENCH3TH前缀获得所有课程。 我试过了 var resultSet = $.grep(courses, function(e){ return e.code == ‘ENCH3TH/’; }); ..无济于事(请注意在’ENCH3TH’之后使用’/’作为通配符)。