1

我有一个商店,它加载了一个显示州名、首都和寒冷天气的网格。

我还有一个复选框,根据“寒冷天气”列的“是”值过滤商店。

当我单击复选框时,网格会过滤并显示具有“是”的状态,但是当我取消选中复选框时,它什么也不做。

如何恢复商店以显示以前的商店?下面是我的复选框。请帮忙。

items: [
    {
        xtype: 'checkboxfield',
        boxLabel: 'Show only Cold State',
        scope: this,
        handler: function (field, value) {
            scope: this,
            this.checkValue = field.getValue();
            console.log(this.checkValue);
            if (this.checkValue == true) {
                this.store.filter('Cold', 'Yes');
            }
            else if (this.checkValue == false) {
            }
        },

更新的代码- 当我这样做时,我得到这个错误

类型错误:tempstore1 未定义

items: [
    {
        xtype: 'checkboxfield',
        boxLabel: 'Show only Cold State',
        scope: this,
        handler: function (field, value) {
            scope: this,
            this.checkValue = field.getValue();
            console.log(this.checkValue);
            if (this.checkValue == true) {
                var tempstore1 = Ext.StoreMgr.lookup('store');
                tempstore1.filters.add('CheckBoxFilter', new Ext.util.Filter({
                    property: 'Cold',
                    value: 'Yes',
                    root: 'myTable'
                }));
                console.log('here');
                tempstore1.load();
            }
            else if (this.checkValue == false) {
                this.store.filters.removeAtKey('CheckBoxFilter');
            }
        },

第二次更新- 现在我收到这个错误

TypeError: a.getRoot.call(a, d) 未定义

代替

var tempstore1 = Ext.StoreMgr.lookup('store');

我在用

var tempstore1 = Ext.getCmp('GridArea1').store;

GridArea1是我的网格面板的 id。

第三次更新- 现在我得到这个错误

var tempstore1 = Ext.getCmp('GridArea1').getStore();

来自chrome调试器的错误...“true”和“here”是我的console.log,“h”部分也是如此...这是tempstore1拥有的而不是我的数据..

true
h {hasListeners: e, scope: h, loading: false, events: Object, eventsSuspended: false...}
这里未捕获类型错误
:无法读取未定义的属性“冷”

4

1 回答 1

5

你需要使用clearFilter()

xtype: 'checkboxfield',
boxLabel: 'Show only Cold State',
scope: this,
handler: function (field, value) {
    this.checkValue = field.getValue();
    console.log(this.checkValue);
    if (this.checkValue == true) {
        this.store.filter('Cold', 'Yes');
    }
    else if (this.checkValue == false) {
        this.store.clearFilter();
    }
}

可以删除特定的过滤器(clearFilter()全部删除)。不要使用该store.filter('property_to_filter','value')方法,而是使用:

store.filters.add('Coldfilter', new Ext.util.Filter({
    property: 'Cold',
    value: 'Yes',
    root: 'data'
}));
store.load();

要删除过滤器,请使用:

store.filters.removeAtKey('Coldfilter');

文档中没有任何内容root: 'data'要添加到过滤器中,现在它可以工作了:http: //jsfiddle.net/vrVRP/2/

于 2012-11-14T21:32:14.137 回答