【问题标题】:extjs 4.2.1 - Toolbar and delegating click events to buttonsextjs 4.2.1 - 工具栏和将点击事件委托给按钮
【发布时间】:2014-01-12 02:35:29
【问题描述】:

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

我有一个工具栏,里面有多个按钮。我将如何将点击事件委托给工具栏中的每个按钮,而无需编写如下内容:

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

每个按钮?

【问题讨论】:

  • 我不是。我的计划是让 Toolbar 功能有点像 TabPanel,所以我需要做的就是在不同的面板之间切换。

标签: javascript html css button extjs


【解决方案1】:

根据您的 cmets,我会这样做:

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

});

【讨论】:

  • 我最终使用了 MVC :\ 但是还是谢谢。我想这以后会派上用场的。
  • 方法还是有点类似的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多