【问题标题】:Store filter in sencha touch将过滤器存储在煎茶触摸中
【发布时间】:2018-04-14 15:10:48
【问题描述】:

我的商店有结构:

Ext.create('Ext.data.Store', {
    fields: [
        'title'
    ],
    data: [{
        title: 'ABC'
    }, {
        title: 'ABC2'
    }, {
        title: 'ABC3'
    }, {
        title: 'ABC4'
    }, {
        title: 'ABC5'
    }, {
        title: 'ABC6'
    }]
});

因此,当我加载此商店列表时,会填充所有 6 条记录。

我只是想在单击按钮时过滤此商店我只是想从这 6 条记录中获取一些选定的记录 可以吗。

给我一​​些想法或工作代码。

【问题讨论】:

  • 根据标题选择记录?
  • 其实我想在列表视图中显示这条记录...请您提供工作代码或一些框架代码...谢谢

标签: sencha-touch-2


【解决方案1】:

根据标题过滤商店

Ext.getStore('storeId').filter("title", "ABC3");

清除过滤器

 Ext.getStore('storeId').clearFilter();

见店铺filterdoc

更新

Ext.getStore('storeId').filterBy(function(record){
   var title = record.get('title');
   if(title == "ABC" || title == "ABC1" || title == "ABC2")
      return record;
});

【讨论】:

  • 这样我只会在列表视图中获得单条记录,即“ABC3”,但我想获得多条记录但不是全部..感谢您的回复
  • @VInayak 多条记录基于什么?
  • 多条记录意味着当我使用以下代码时 Ext.getStore('storeId').filter("title", "ABC3");在列表视图中,我只有一个标题为“ABC3”但实际上我想在列表视图中获得 ABC ABC1 ABC2 不是全部。抱歉给您带来这么多麻烦,感谢您的回复。
  • @VInayak 对于您需要使用 filterBy 的那种条件。请参阅我的答案中的更新
  • 谢谢,这正是我所需要的。谢谢
【解决方案2】:

我的方法是在我点击按钮时在商店上设置一个过滤器。在我的情况下,它是一个选择字段,并且在更改事件中我与选择字段中的当前值进行比较

    onChangeStatusSelectfield: function (newValue, oldValue) {
    var store = Ext.getStore('CustomVacationRequest');
    console.log('Accepted Filter');
    newValue = this.getStatusSelectfield().getValue();
    console.log(store, newValue);
    store.clearFilter();
    if (store != null);
    store.filter(function (record) {
        if (newValue == record.data.status) { //your data from the store compared to 
                                              //the value from the selectfield
            return true; 
        }
        Ext.getCmp("VacationRequestsManagerList").refresh() //refresh your list   
});

},

这只是我控制器的一部分。根据您自己的选择和需要处理事件、按钮和存储。祝你好运!

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 2012-11-04
    • 1970-01-01
    相关资源
    最近更新 更多