简体   繁体   English

ExtJS5 存储过滤器“未捕获的类型错误:无法读取未定义的属性‘get’”

[英]ExtJS5 Store filter "Uncaught TypeError: Cannot read property 'get' of undefined"

I'm using the gpl version of extjs5.1.1 without sencha cmd.我使用的是 extjs5.1.1 的 gpl 版本,没有 sencha cmd。
In my application a Grid displays correctly a Store.在我的应用程序中,网格正确显示了商店。
In the window, there is a checkbox wich code is :在窗口中,有一个复选框,其代码为:

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

The variable store points to the grid store correctly.变量store指向电网商店正确。 I can see the messages 'clearFilter' and 'rightFilter' in the console.我可以在控制台中看到消息“clearFilter”和“rightFilter”。

The store code:店铺代码:

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'
        }
    }
});

On window call, the checkbox is unchecked and the filter is active because the grid listeners is:在窗口调用时,复选框未选中且过滤器处于活动状态,因为网格侦听器是:

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

The first time I check the checkbox the filter is cleared correctly and the message 'clearFilter' appears in the console.我第一次选中复选框时,过滤器被正确清除,控制台中出现消息“clearFilter”。 When I uncheck it, the message 'rightFilter' appears too, but the filter does not anything in the grid... and the error message "Uncaught TypeError: Cannot read property 'get' of undefined" appears.当我取消选中它时,也会出现消息“rightFilter”,但过滤器在网格中没有任何内容......并且出现错误消息“Uncaught TypeError: Cannot read property 'get' of undefined”。

Where am I wrong?我哪里错了?

Edit : Actually the filter function only works fine once.编辑:实际上过滤器功能只能正常工作一次。 It does not work any more after clearFilter is called...调用clearFilter后它不再起作用......
I tried with addFilter / removeFilter with the same result.我尝试使用addFilter / removeFilter ,结果相同。
My next try will be setDisable .我的下一次尝试将是setDisable
If someone has any (other) idea...如果有人有任何(其他)想法......

Edit 2: Test case in fiddle编辑 2:小提琴中的测试用例
Now I know that the problem comes from function call in the render function.现在我知道问题来自渲染函数中的函数调用。 When this call is not done, the checkbox works perfectly, but on show, the checkbox state does not correspond to the display and I want to hide filtered items on show.当此调用未完成时,复选框工作正常,但在显示时,复选框状态与显示不对应,我想在显示时隐藏过滤的项目。

Any Idea ?任何的想法 ?

The filter function cannot be called just after the load, that's why load in render and filter in viewready (in afterrender it doesn't work either). filter 函数不能在加载后立即调用,这就是为什么在渲染中加载并在 viewready 中过滤(在 afterrender 中它也不起作用)。 The problem is solved !!问题已经解决了 !!

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

The problem is in this line is with this .问题是,在这条线是与有关。

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

Can you please change the above code to你能把上面的代码改成

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

and the grid listener to pass store和传递存储的网格侦听器

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

and the calling from combobox to以及从组合框到

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Extjs5 treepanel [未捕获的TypeError:无法读取未定义的属性&#39;create&#39;] - Extjs5 treepanel [Uncaught TypeError: Cannot read property 'create' of undefined] EXTJS 6 Modern:缓冲存储+网格:未捕获的TypeError:无法读取未定义的属性&#39;length&#39; - EXTJS 6 Modern: buffered store + grid: Uncaught TypeError: Cannot read property 'length' of undefined ExtJs错误:未捕获TypeError:无法读取未定义的属性&#39;removeCls&#39; - ExtJs Error: Uncaught TypeError: Cannot read property 'removeCls' of undefined extjs 4Uncaught TypeError:无法读取未定义的属性“ items” - extjs 4Uncaught TypeError: Cannot read property 'items' of undefined ExtJS:未捕获的TypeError:无法读取未定义的属性“作用域” - ExtJS: Uncaught TypeError: Cannot read property 'scope' of undefined 未捕获的TypeError:无法读取未定义的属性&#39;responseText&#39; - Uncaught TypeError: Cannot read property 'responseText' of undefined 未捕获的类型错误:无法读取未定义的属性“dom” - Uncaught TypeError: Cannot read property 'dom' of undefined 未捕获的TypeError:无法读取未定义的属性“位置” - Uncaught TypeError: Cannot read property 'location' of undefined 未捕获的类型错误:无法读取未定义的属性“销毁” - Uncaught TypeError: Cannot read property 'destroy' of undefined 未捕获的TypeError:无法读取未定义的属性&#39;getProxy&#39; - Uncaught TypeError: Cannot read property 'getProxy' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM