EXTJS combobox change even code executed on page load

旧城冷巷雨未停 提交于 2019-12-11 19:37:05

问题


I have created class for combobox, which object can be created whenever combobox need in project.

now for every change event of every combo there can be different things to do, so I have not written any code in my combo class for combo change event.

I need something like I can assign code to combo change event when i create it or after creating.

So i write below code .

Ext.getCmp('combo1').on('change', Ext.getCmp('grid').getfilteredStore());

But issue with this code is : Ext.getCmp('grid').getfilteredStore() get triggered on page load only, not on change of combo.

Below is code which create combo whenever required

Ext.create('Comboclass', { 
        id: 'comboId'});

Below is combo class

Ext.define('Comboclass', {
    extend: 'Ext.Container',

    initComponent: function () {

        Ext.apply(this, {
            items: [{
                xtype: 'combo',
                id: this.id,
                store: store1
                listeners: {
                    beforeselect : function (combo, r, index) {
                        if (r.data.id && r.data.id < 0) {
                            r.data.selectable = false;
                            return r.data.selectable;
                        }
                    },
                    change: function (field, newValue, oldValue) {
                        console.log('in dropdown');
                    }
                }
            }]
        });
        this.callParent(arguments);
    }
});

Can any one help to solve this issue?

Thanks in advance.


回答1:


Because you're executing the function. on expects a reference to a function.

It's the difference between:

var x = fn(); // x now contains the result of fn
var y = fn; // y now points to the function

You need to remove the last parentheses:

Ext.getCmp('combo1').on('change', Ext.getCmp('grid').getfilteredStore);



来源:https://stackoverflow.com/questions/21521112/extjs-combobox-change-even-code-executed-on-page-load

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!