2017-10-04 113 views
1

我在filters配置商店的指定的过滤器:ExtJS的4:动态存储滤波

Ext.define('Record', { 
    extend: 'Ext.data.Model', 
    fields: [{ 
     name: 'value', 
     type: 'number' 
    }] 
}); 

Ext.create('Ext.data.Store', { 
    id: 'store', 
    model: 'Record', 

    filters: [ 
     function(item) { 
      return item.get('value') > 2; 
     } 
    ], 

    sorters: [{ 
     property: 'value', 
     direction: 'DESC' 
    }], 

    data: [{ 
     value: 2, 
    }, { 
     value: 1 
    }, { 
     value: 3 
    }] 
}); 

Ext.create('Ext.view.View', { 
    store: Ext.data.StoreManager.lookup('store'), 
    tpl: new Ext.XTemplate(
     '<tpl foreach=".">', 
      '<div class="record">{value}</div>', 
     '</tpl>' 
    ), 
    itemSelector: '.record', 
    emptyText: 'No records', 
    renderTo: Ext.getBody() 
}); 

如果我显式调用filter()在商店仅适用。 filterOnLoad未设置,并且默认为true,因此必须过滤商店。我如何保持商店始终过滤(每当执行任何CRU操作并加载后)?

回答

1

要做到这一点需要它的听众添加到存储上添加和更新事件:

listeners: { 
    add: function(store) { 
     store.filter(); 
    }, 

    update: function(store) { 
     store.filter(); 
    } 
}, 
+0

接受你的答案。 –

+1

@AkinOkegbile我不能明天。 –