2013-12-20 10 views
1

我有一个web服务,这个服务返回json数据。
例子:javascript数组列表过滤器不工作

{ 
    "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和它的作品。但我尝试了populer字段的过滤器,但它不工作。我想因为变量类型:populer返回布尔值。

这是工作:

NewMobile.globals.products.filter('groupId',200000); 

,但是这是不工作

NewMobile.globals.products.filter("populer",true); 

谁能帮助我吗?

+0

它仅仅是一个例如 – cptc

+0

数据的一部分,所以,什么是'NewMobile.globals.products.filter' – C5H8NNaO4

+0

NewMobile.globals.products是一个对象。 json数据存储在这里 – cptc

回答

0

每当我跑项目,这个旧的代码添加一个新的过滤器。

NewMobile.globals.products.clearFilter();我用这个和问题解决了。 clearFilter正在清除旧的过滤器。 感谢您的所有建议和对不起我的英文:)

0

如果NewMobile.globals.products是一个标准阵列然后附着到Array对象的过滤器的方法应该是这样来完成:

NewMobile.globals.products.filter(function(el) { return el.populer === true; }) 

因为过滤功能接受一个函数,而不是一个场作为它的论据。

您可以阅读MDN文档浏览: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

+0

谢谢你的回答,但我看到了这个链接,我试过但没有工作。您的代码太多了。 – cptc

+0

也许您在浏览器中遇到了一些问题,但过滤方法相对较新且不受到任何支持 –

+0

NewMobile.globals.products.filter('groupId',200000);但这工作? – cptc

0

@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; 
    } 

});