touch - Sencha touch 2 filterby() 不更新记录

标签 touch sencha-touch-2

我在选项卡式面板应用程序的一个页面上有一个嵌套列表,该应用程序从“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'
        }
    }
}

最佳答案

  1. 无需每次都重新创建正则表达式,将其缓存在外部。

  2. 您可以大大简化代码(见下文)。

  3. 为什么要在之后直接调用 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/

相关文章:

javascript - Sencha touch 2 - 自定义组件开发数据项未从存储加载值

javascript - jquery 将如何为移动设备实现触摸事件?

html - 既然 Chrome 未通过标准测试,如何测试触摸事件?

android - 切换到轴控件到屏幕按钮控件时动画不起作用

sencha-touch - 表单提交不起作用

sencha-touch - 覆盖失败并出现错误

html - 如何删除/忽略 :hover css style on touch devices

javascript - 使用 JavaScript 检测 'touch screen' 设备的最佳方法是什么?

cordova - 如何将 Sencha Touch 2 集成到 Cordova (Phonegap) 项目中

css - 工具栏中的样式标题 sencha touch