Extjs 4.2将处理程序附加到面板工具不起作用

时间:2013-07-31 11:22:24

标签: extjs extjs4.2

这是我正在做的事情:

Ext.define('NG.view.taxinvoice.Widget', {
    extend: 'NG.code.portal.Portlet',
    alias: 'widget.taxinvoicewidget',
    layout: 'card',

    tools: [{
        type: 'gear',
        scope: this,
        callback: 'onGearToolClick'
    }],

    items: [{
        xtype: 'taxinvoicelist'
    }, {
        html: 'taxinvoicegraph'
    }],

    onGearToolClick: function (panel) {
        alert('1111') This is not invoked!
    }
});

警告声明永远不会被解雇...... 你能告诉我为什么吗?

更新

好吧它的工作方式是使用@kevhender接受的答案:

Ext.define('NG.view.taxinvoice.Widget',{     extend:'NG.code.portal.Portlet',     别名:'widget.taxinvoicewidget',     布局:'卡',

items: [{
    xtype: 'taxinvoicelist'
}, {
    html: 'taxinvoicegraph'
}],

initComponent: function () {
    this.tools = [{
        type: 'gear',
        scope: this,
        callback: 'onGearToolClick'
    }];

    this.callParent(arguments);
},

onGearToolClick: function (panel) {
    alert('1111') Now it fires :)
}

});

1 个答案:

答案 0 :(得分:0)

我不相信框架支持使用字符串来指定回调函数的名称,您应该使用实际的函数。如果您想使用成员函数,则必须在tools中定义initComponent

initComponent: function() {
    this.tools = [{
        type: 'gear',
        scope: this,
        callback: this.onGearToolClick
    }];
    this.callParent(arguments);
}

如果您使用匿名函数,也可以按现在的方式执行此操作:

Ext.define('NG.view.taxinvoice.Widget', {
    extend: 'NG.code.portal.Portlet',
    alias: 'widget.taxinvoicewidget',
    layout: 'card',

    tools: [{
        type: 'gear',
        scope: this,
        callback: function() {
            //define fn here
        }
    }],

    ...
});
相关问题