我在选项卡式面板应用程序的一个页面上有一个嵌套列表,该应用程序从“offices.json”中提取数据
我希望能够在用户单击工具栏按钮时过滤此列表。但是,我的 filterBy() 函数不会更新我可以看到的商店和办公室列表,即使我可以在控制台中看到它正在迭代记录并查找匹配项。我究竟做错了什么? (是的,我尝试在 filterBy 之前和之后执行 s.load() 但无济于事!)
toolbar:{
items:[{
text: 'Near you',
id: 'btnNearYou',
xtype: 'button',
handler: function() {
s = Ext.StoreMgr.get('offices');
s._proxy._url = 'officesFLAT.json';
console.log("trying to filter");
s.filterBy(function(record) {
var search = new RegExp("Altrincham", 'i');
if(record.get('text').match(search)){
console.log("did Match");
return true;
}else {
console.log("didnt Match");
return false;
}
});
s.load();
}
}]
根据记录,我像这样定义我的商店:
store: {
type: 'tree',
model: 'ListItem',
id: 'offices',
defaultRootProperty: 'items',
proxy: {
type: 'ajax',
root: {},
url: 'offices.json',
reader: {
type: 'json',
rootProperty: 'items'
}
}
}
最佳答案
无需每次都重新创建正则表达式,将其缓存在外部。
您可以大大简化代码(见下文)。
为什么要在之后直接调用 load?这会将其发送到服务器,并且服务器只会检索相同的数据集。
toolbar: {
items: [{
text: 'Near you',
id: 'btnNearYou',
xtype: 'button',
handler: function() {
s = Ext.StoreMgr.get('offices');
s._proxy._url = 'officesFLAT.json';
var search = /Altrincham/i;
s.filterBy(function(record) {
return !!record.get('text').match(search);
});
}
}]
}
关于touch - Sencha touch 2 filterby() 不更新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13463486/