javascript数组列表筛选器不工作
我有一个web服务,该服务返回json数据。javascript数组列表筛选器不工作,javascript,extjs,Javascript,Extjs,我有一个web服务,该服务返回json数据。 例如: { "id": -65000, "name": "SIK KULLANILANLAR", "stockCode": null, "groupId": 200000, "price": 0.0, "color": null, "type": 1, "mustModGrpCount": 0, "mustModGroups": "0", "order
例如:
{
"id": -65000,
"name": "SIK KULLANILANLAR",
"stockCode": null,
"groupId": 200000,
"price": 0.0,
"color": null,
"type": 1,
"mustModGrpCount": 0,
"mustModGroups": "0",
"order": 0,
"campCount": 0,
"populer": false
}, {
"id": 3882,
"name": "MILLER",
"stockCode": "ALK001",
"groupId": 200042,
"price": 8.9,
"color": "aliceblue",
"type": 3,
"mustModGrpCount": 0,
"mustModGroups": "",
"order": 0,
"campCount": 0,
"populer": false
}, {
"id": 3883,
"name": "EFES PILSEN 33 CL",
"stockCode": "ALK002",
"groupId": 200042,
"price": 7.9,
"color": "aliceblue",
"type": 3,
"mustModGrpCount": 0,
"mustModGroups": "",
"order": 0,
"campCount": 0,
"populer": false
}
我正在为groupId
过滤这些数据,它可以正常工作。但我尝试了popper
字段的过滤器,但它不起作用。我猜是因为变量类型:popper
返回布尔值
这是有效的:
NewMobile.globals.products.filter('groupId',200000);
但这是行不通的
NewMobile.globals.products.filter("populer",true);
有人能帮我吗?如果NewMobile.globals.products是一个标准数组,则附加到数组对象的筛选方法应如下所示:
NewMobile.globals.products.filter(function(el) { return el.populer === true; })
因为filter函数的参数是函数,而不是字段
您可以在此处阅读MDN文档:
@Akori
NewMobile.globals = {
mesaj: 'selam',
action: '',
server: '192.168.50.70',
branchCode: '0',
activeTable: '',
activeFolio: '0',
activeTableGroup: '',
activeMustGroup: -1,
activePid: 0,
activeMustGroupString: 0,
activeMustDesc: '',
activeMustArray: [],
activeCampProduct: '',
products: undefined,
rePrint: '',
activePax: 1,
uuid: 'tanimsiz',
activeSkin: 'Krem'
};
这是启动函数变量
这是我的要求
NewMobile.globals.products = Ext.create('NewMobile.store.PorductStore');
NewMobile.globals.products.setProxy({url: "http://" + NewMobile.globals.server + ':1002/zulu/newmobile/data.aspx?act=getAllProducts'});
NewMobile.globals.products.getProxy();
NewMobile.globals.products.load(function(a, records, c, d, e){
if (c !== true) {
Ext.Viewport.setMasked(false);
Ext.Msg.alert('uyarı', NewMobile.message.connectionError, Ext.emptyFn);
return;
}
});
每当我运行project时,这段旧代码都会添加一个新过滤器 NewMobile.globals.products.clearFilter();我用这个解决了问题。 clearFilter正在清除旧的筛选器。
谢谢你的建议,对不起我的英文:)这只是数据的一部分,例如,什么是
NewMobile.globals.products.filter
NewMobile.globals.products是一个对象。存储在这里的json数据及其过滤器方法做什么?我请求将所有产品发送到NewMobile.globals.products。和筛选方法筛选值。exp:products.filter(“字段名”、“筛选值”);它只是显示过滤后的值。谢谢你的回答,但我以前看到过这个链接,我试过了,但没有成功。您的代码也是..可能您的浏览器有一些问题,筛选器方法相对较新,不支持NewMobile.globals.products.filter('groupId',200000);但这是可行的?也许你有一些自定义的过滤函数:/,你可以通过键入NewMobile.globals.products.filter===Array.prototype来检查这一点。filter@Igor,我怀疑他可能正在使用商店的过滤功能:filter([filters],[value])