Javascript extjs 4.2.1-工具栏和将单击事件委托给按钮

Javascript extjs 4.2.1-工具栏和将单击事件委托给按钮,javascript,html,css,button,extjs,Javascript,Html,Css,Button,Extjs,我在谷歌上搜索,但没有找到这个问题的任何答案 我有一个工具栏,里面有多个按钮。如何将单击事件委派给工具栏中的每个按钮,而不必编写以下内容: { xtype: 'button', text: 'Click me', handler: function() { // do something... } } 对于每个按钮?根据您的评论,我会这样做: Ext.define('MyContainer', { extend: 'Ext.contain

我在谷歌上搜索,但没有找到这个问题的任何答案

我有一个工具栏,里面有多个按钮。如何将单击事件委派给工具栏中的每个按钮,而不必编写以下内容:

{
    xtype: 'button',
    text: 'Click me',
    handler: function() {
        // do something...
    }
}

对于每个按钮?

根据您的评论,我会这样做:

Ext.define('MyContainer', {
    extend: 'Ext.container.Container',

    initComponent: function() {
        var handler = this.handleButton;
        this.defaultType = 'button';
        this.items = [{
            text: 'A',
            key: 'itemA',
            handler: handler
        }, {
            text: 'B',
            key: 'itemB',
            handler: handler
        }, {
            text: 'C',
            key: 'itemC',
            handler: handler
        }, {
            text: 'D',
            key: 'itemD',
            handler: handler
        }];
        this.callParent();
    },

    handleButton: function(btn) {
        console.log(btn.key);
        // do something with key
    }
});

Ext.onReady(function() {

    new MyContainer({
        renderTo: document.body
    });

});

我不是。我的计划是让工具栏的功能有点像TabPanel,所以我所需要做的就是在不同的面板之间切换。我最终使用了MVC:\但是无论如何还是要谢谢你。我想这会在以后派上用场的。方法仍然有些相似。