gpt4 book ai didi

javascript - extjs 4.2.1 - 工具栏并将点击事件委托(delegate)给按钮

转载 作者:行者123 更新时间:2023-11-30 12:50:39 25 4
gpt4 key购买 nike

我在 Google 上搜索但没有找到这个问题的任何答案...

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

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

});

关于javascript - extjs 4.2.1 - 工具栏并将点击事件委托(delegate)给按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21070636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com