0

我正在按代码过滤股票列表,但它不起作用。也许代码有问题?我错过了什么?以下是我尝试过的一些事情:

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();
    }
}
4

2 回答 2

3

事实证明,我们必须在商店中禁用远程过滤,这应该默认为 false,但事实并非如此:

this.getOrderList().getStore().setRemoteFilter(false);
于 2012-10-03T13:25:43.813 回答
1

其中之一应该工作

// 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
于 2012-07-31T07:00:53.910 回答