ExtJS Store.filterBy在Store.filter工作的地方失败
我查看了文档,似乎无法理解为什么store.filter()可以工作,直到我添加了一个函数,filterBy()也失败了 我需要过滤器检查记录中的2项内容。 我需要检查:ExtJS Store.filterBy在Store.filter工作的地方失败,extjs,extjs4,extjs4.1,Extjs,Extjs4,Extjs4.1,我查看了文档,似乎无法理解为什么store.filter()可以工作,直到我添加了一个函数,filterBy()也失败了 我需要过滤器检查记录中的2项内容。 我需要检查: if(deviceMsgId == 1 || messageType == 'TEXT_MESSAGE') 存储: var msgStore = Ext.create('p7_ui_static.store.DeviceMessageStore', { id: 'messageLogStore', st
if(deviceMsgId == 1 || messageType == 'TEXT_MESSAGE')
存储:
var msgStore = Ext.create('p7_ui_static.store.DeviceMessageStore', {
id: 'messageLogStore',
storeId: storeId,
remoteFilter: false,
autoLoad:false,
...
...
});
Ext.define('p7_ui_static.model.DeviceMessage', {
extend: 'Ext.data.Model',
...
...
fields: [
{
name: 'deviceMessageTypeId'
},
{
name: 'messageType'
},
{
...
}
]
});
型号:
var msgStore = Ext.create('p7_ui_static.store.DeviceMessageStore', {
id: 'messageLogStore',
storeId: storeId,
remoteFilter: false,
autoLoad:false,
...
...
});
Ext.define('p7_ui_static.model.DeviceMessage', {
extend: 'Ext.data.Model',
...
...
fields: [
{
name: 'deviceMessageTypeId'
},
{
name: 'messageType'
},
{
...
}
]
});
此过滤器工作->
msgStore.clearFilter(true);
msgStore.filter([
{ property: 'deviceMsgId', value : 1 }
]);
msgStore.filterBy(function(record){
return record.get('deviceMsgId' == 1)
});
过滤器(过滤器,[值])
msgStore.clearFilter(true);
msgStore.filter([
{ property: 'deviceMsgId', value : 1 }
]);
msgStore.filterBy(function(record){
return record.get('deviceMsgId' == 1)
});
但此筛选器失败->
msgStore.clearFilter(true);
msgStore.filter([
{ property: 'deviceMsgId', value : 1 }
]);
msgStore.filterBy(function(record){
return record.get('deviceMsgId' == 1)
});
过滤器比(fn,[范围])
msgStore.clearFilter(true);
msgStore.filter([
{ property: 'deviceMsgId', value : 1 }
]);
msgStore.filterBy(function(record){
return record.get('deviceMsgId' == 1)
});
下面是一个使用filterBy的示例
msgStore.filterBy(function (record){
if ((record.get('deviceMsgId'))===1 ||
record.get('messageType')==='TEXT_MESSAGE'){
return true;
}
});
此外,作为奖励,您可以通过以下代码轻松地按属性筛选商店:
msgStore.filter('deviceMsgId',1);
编辑:再次查看文档后,您返回true的结果似乎是正确的。如果没有调用该函数,控制台中是否会抛出任何错误?您没有发布数据。你说“失败”是什么意思?函数从未被调用?@Evan Trimbol当我说“失败”时,我的意思是过滤器没有过滤。条件{filterFn:function(item){return item.get(“deviceMsgId”)==1}}返回所有项,而不仅仅是deviceMsgId==1的项。您已将存储配置为远程筛选。谢谢,我明白您的意思。我仍然不能使用一个过滤器。这个方法永远也达不到。。我还是不知道为什么。然而,我能够使用一个reg filter调用,Fn:…我发布了我的解决方案,并按照您的建议将布尔值作为返回值。