ExtJS5存储过滤器" Uncaught TypeError:无法读取属性' get'未定义"

时间:2015-06-14 20:39:39

标签: extjs extjs5

我使用没有sencha cmd的gpl版本的extjs5.1.1 在我的应用程序中,Grid正确显示了一个商店 在窗口中,有一个代码为的复选框:

{
    xtype    : 'checkbox',
    itemId   : 'employeeFilter',
    value    : false,
    boxLabel : 'Show inaktiv users',
    margin   : '0 5 0 5',
    listeners: {
        change: function(checkbox, newValue, oldValue, eOpts) {
            var store = this.up('window').getComponent('employeeGrid').getStore();
            if (newValue) {
                console.log('clearFilter');
                store.clearFilter();
            } else {
                console.log('rightFilter');
                store.rightFilter();
            }
        }
    }
}]

变量store正确指向网格存储。我可以看到消息< clearFilter'和' rightFilter'在控制台中。

商店代码:

Ext.define('Chronos.store.manage.Employees', {
    extend : 'Ext.data.Store',

    model      : 'Chronos.model.manage.Employee',
    autoLoad   : false,
    autoSync   : true,
    sortOnLoad : false,
    pageSize   : 0,

    rightFilter: function() {
        this.filterBy(function(record) {
            return record.get('rights') >= 0;
        });
    },

    proxy : {
        type   : 'ajax', // Ext.data.proxy.Ajax
        api    : {
            create  : 'api/management/employees.create.php',
            read    : 'api/management/employees.read.php',
            update  : 'api/management/employees.update.php',
            destroy : 'api/management/employees.destroy.php'
        },
        reader : {
            type         : 'json', // Ext.data.reader.Json
            rootProperty : 'records'
        },
        writer : {
            type         : 'json', // Ext.data.writer.Json
            encode       : true,
            rootProperty : 'record'
        }
    }
});

在窗口调用中,取消选中该复选框,并且筛选器处于活动状态,因为网格侦听器是:

    listeners: {
        render: function() {
            this.getStore().load();
            this.getStore().rightFilter(); // <<<<< if the function is called here, the problem exists, if not, the filter works perfectly !
        }
    },

我第一次选中复选框时,过滤器被正确清除,并且消息“清除过滤器”#39;出现在控制台中。当我取消选中它时,消息&#39; rightFilter&#39;也出现了,但过滤器在网格中没有任何内容......并且错误消息&#34;未捕获的TypeError:无法读取属性&#39; get&#39;未定义&#34;出现。

我哪里错了?

编辑:实际上,过滤功能只能正常工作一次。调用clearFilter后,它不再起作用了。
我尝试使用addFilter / removeFilter并获得相同的结果 我的下一次尝试将是setDisable 如果有人有任何(其他)想法......

编辑2:测试用例in fiddle
现在我知道问题来自render函数中的函数调用。如果没有完成此调用,则复选框可以正常工作,但是在显示时,复选框状态与显示不对应,我想在显示时隐藏已过滤的项目。

任何想法?

2 个答案:

答案 0 :(得分:1)

在加载后不能调用过滤器函数,这就是为什么在视图中加载渲染和过滤器的原因(在后期它也不起作用)。问题解决了!!

    listeners: {
        render: function() {
            this.getStore().load();
        },
        viewready: function() {
            this.getStore().rightFilter();
        }
    }

答案 1 :(得分:0)

这一行的问题在于这个

rightFilter: function() {
        this.filterBy(function(record) { // <<<<< this line sends an error the second time the function is called
            return record.get('rights') >= 0;
        });
    },

您能否将上述代码更改为

rightFilter: function(me) {
me.filterBy(function(record) { // <<<<< this line sends an error the second time the function is called
return record.get('rights') >= 0;
});
},

和网格侦听器传递商店

listeners: {
        render: function() {
            this.getStore().load();
            this.getStore().rightFilter(this.getStore());
        }
    },

以及从组合框到

的调用
if (newValue) {
                console.log('clearFilter');
                store.clearFilter();
            } else {
                console.log('rightFilter');
                store.rightFilter(store);
            }