2015-05-26 51 views
-1

如何在extjs中存儲過濾器?如何在extjs中過濾商店?

fieldLabel : 'Status', 
xtype   : 'combo', 
name   : 'status', 
store : new Ext.data.ArrayStore({ fields : ['status'], data : [['A'],['B'],['C']), 
displayField : 'status', 
valueField : 'status', 
autoSelect  : true, 
typeAhead  : true, 
validateOnBlur: true, 
queryMode : 'local' 

我需要根據一些條件做過濾器..樣品

if(Somecondition) 
.... filter A and B 
elseif(Somecondition) 
    filter B 
else 
    Filter only A and C 

回答

0

我不太清楚到底是什麼你正在嘗試做的,但這裏是會改變的值的解決方案組合框到三個選項的特定子集。如果「有條件」被認爲是過濾一組任意數據,那麼我需要更多地瞭解「有條件」與數據的關係。

{ 
      fieldLabel: 'Status', 
      xtype: 'combo', 
      name: 'status', 
      store: Ext.create('Ext.data.Store', { 
       fields: ['status'], 
       data: [{ 
        'status': 'A' 
       }, { 
        'status': 'B' 
       }, { 
        'status': 'C' 
       }, ] 
      }), 
      displayField: 'status', 
      valueField: 'status', 
      autoSelect: true, 
      typeAhead: true, 
      validateOnBlur: true, 
      queryMode: 'local', 
      listeners: { 
       beforerender: function(t) { 
        if (Somecondition) { 
         t.store.loadData([{ 
          'status': 'A' 
         }, { 
          'status': 'B' 
         }]) 
        } else if (Somecondition) { 
         t.store.loadData([{ 
          'status': 'B' 
         }]) 
        } else { 
         t.store.loadData([{ 
          'status': 'A' 
         }, { 
          'status': 'C' 
         }]) 
        } 

       } 
      } 
     } 
+0

這隻我需要..謝謝你的幫助..它的工作很好 – Deepak

0
statusStore.clearFliter(); 
statusStore.filter(function(r) { 
      var value = r.get('status'); 
      return (value == "A" || value == "B"); 
    }); 

採用存儲濾波器還我得到的結果。

ClearFliter將刪除該商店中的以前的值。