如何在 extjs 中过滤存储?

How to Filter store in 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

我不太确定您要做什么,但这里有一个解决方案,可以将组合框的值更改为三个选项的特定子集。如果 "Somecondition" 应该过滤任意一组数据,那么我将需要更多地了解 "Somecondition" 与数据的关系。

{
            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'
                        }])
                    }

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

使用商店过滤器我也得到了结果。

ClearFliter 用于删除该存储中的先前值。