【问题标题】:Extjs 4.2 attach an handler to a panel tool do not workExtjs 4.2 将处理程序附加到面板工具不起作用
【发布时间】:2013-07-31 11:22:23
【问题描述】:

这是我正在做的事情:

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', { 扩展:'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 :)
}

});

【问题讨论】:

    标签: extjs extjs4.2


    【解决方案1】:

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

    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
            }
        }],
    
        ...
    });
    

    【讨论】:

    • 我不想在回调中定义函数,我希望它驻留在面板定义中。
    • 并且框架确实支持将字符串作为回调传递,请参阅Ext.panel.Tool
    • 我已经接受了你的回答,但你应该知道,从 4.2.1 版开始就允许使用字符串,我已经用我最终完成的内容更新了我的问题。
    • 谢谢,我想他们很快就会朝着这个方向前进。
    猜你喜欢
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2013-01-10
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    相关资源
    最近更新 更多