2012-07-30 44 views
0

我正在按符号筛选股票列表,但它不起作用。代码可能有问题吗?我错过了什么?这里有一些事情我已经试过:如何筛选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(); 
    } 
} 

回答

3

事实证明,我们不得不在商店,这是应该默认为false禁用远程过滤功能,但它不是:

this.getOrderList().getStore().setRemoteFilter(false); 
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; 
} 

UPDATE:样的作品:

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 
+0

不幸的是,所有这些工作。传递给orderStore.filterBy的lambda永远不会被调用。如果传递给orderStore.data.filterBy,它会被调用。 filterFn也不会被调用。对第一种方法没有把握,但列表内容不会改变:\ – Vitaly 2012-08-02 09:49:52

+0

好像您已将商店配置为不正确。我更新了样品后,它的工作 – Madman 2012-08-03 07:38:33

+0

谢谢你。你可能是对的。我有一个模型和一个商店,该模型有一个hasMany属性,指向另一个模型。我想,我应该为拥有很多属性的模型创建一个商店。 – Vitaly 2012-08-05 11:27:08