【问题标题】:ExtJS 4: Dynamic store filteringExtJS 4:动态存储过滤
【发布时间】:2018-03-16 01:20:53
【问题描述】:

我在商店的filters 配置中指定了一个过滤器:

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 操作和加载后)?

【问题讨论】:

    标签: extjs extjs4 filtering store


    【解决方案1】:

    为此,需要在添加和更新事件时将侦听器添加到商店:

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

    【讨论】:

    • 接受您的回答。
    • @AkinOkegbile 我明天才能到。
    猜你喜欢
    • 2013-03-31
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    相关资源
    最近更新 更多