繁体   English   中英

如何在Sencha Touch 2中过滤列表?

[英]How to filter a list in Sencha Touch 2?

我正在按交易品种过滤股票清单,但这不起作用。 也许代码有问题? 我错过了什么? 这是我尝试过的一些方法:

function filterBySymbol: function(select, value) {

    var ordersStore = this.getBrokerageOrderHistoryList().getStore();

    ordersStore.clearFilter();

    if (value !== '') {
        ordersStore.data.filterBy(function (record, id) {
            // log to make certain this gets called (and it is)
            console.log(id, record.get('symbol') === value);
            return record.get('symbol') === value;
        });

// Other things I've tried (nothing worked):
// 1)
//          var f = new Ext.util.Filter({
//             filterFn: function(record) {
//                return record.get('symbol') === value;
//             }
//          });
//          ordersStore.filterBy(f);
// 2)
//          ordersStore.filter(function (record) {
//              return record.get('symbol') === value;
//          });
// 3)
//          this.getBrokerageOrderHistoryList().setStore(ordersStore);
//          this.getBrokerageOrderHistoryList().refresh();
    }
}

事实证明,我们必须在存储上禁用远程筛选,该默认应该设置为false,但不是:

this.getOrderList().getStore().setRemoteFilter(false);

其中之一应该工作

// 1
ordersStore.filter("symbol", value);

// 2
ordersStore.filter([    
    { filterFn: function(item) { return item.get("symbol") === value; }}
]);

// 3
ordersStore.filterBy(function(item) { 
return item.get("symbol") === value; 
}

更新:有效的示例:

Ext.define('ST.store.Products', {
    extend: 'Ext.data.Store',

    config: {
        fields: ["title", "category" ],
        storeId: "Products",

        data: [
            { title: 'Text1', category: 'cat1'},
            { title: 'Text2', category: 'cat2'},
            { title: 'Text3', category: 'cat3'},
        ]
    }
});

 console.log("before");
        Ext.getStore("Products").each(function(item){
            console.log(item.data.title);

        });        

        Ext.getStore("Products").filterBy(function(item){
            return item.get('title') == 'Text1';    
        });

        console.log("after");
        var store = Ext.getStore("Products").each(function(item){
            console.log(item.data.title);

        });  

就我而言,我在开发人员控制台中看到以下内容

before 
Text1
Text2
Text3
after
Text1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM