【问题标题】:EXTJS combobox change even code executed on page loadEXTJS 组合框甚至更改页面加载时执行的代码
【发布时间】:2014-02-03 06:35:24
【问题描述】:

我已经为组合框创建了类,可以在项目中需要组合框时创建该对象。

现在对于每个组合的每个更改事件都可以做不同的事情,所以我没有在我的组合类中为组合更改事件编写任何代码。

我需要一些东西,比如我可以在创建组合更改事件时或创建之后为组合更改事件分配代码。

所以我写下面的代码。

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

但此代码的问题是:Ext.getCmp('grid').getfilteredStore() 仅在页面加载时触发,而不是在组合的 change 上触发。

以下是在需要时创建组合的代码

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

下面是组合类

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

谁能帮忙解决这个问题?

提前致谢。

【问题讨论】:

    标签: extjs


    【解决方案1】:

    因为您正在执行该功能。 on 需要对函数的引用。

    区别在于:

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

    你需要去掉最后的括号:

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

    【讨论】:

    • Ext.getCmp('combo1').on('change', Ext.getCmp('grid').getfilteredStore, Ext.getCmp('grid'));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2013-03-31
    相关资源
    最近更新 更多