菜单的其中一个选项被视为“典型”。与大多数人一样,单击第一个菜单项。但对于那些外部案件,还有第二种选择。因此,我想要一个按钮菜单,它具有默认选项,适用于那些不想为“典型”选项单击两次的选项。我在想按钮的处理程序是:
event.stopEvent()
但没有成功。)但如果您点击按钮旁边的下拉图标,您仍然可以访问该菜单。
小提琴here。
Ext.create('Ext.button.Button', {
text: 'Pick One',
menu: {
items: [{
text: 'Thing 1!',
handler: function () {
alert('foo');
}
}, {
text: 'Thing 2!',
handler: function () {
alert('bar');
}
}]
},
handler: function (theButton, event) {
//stop the menu from showing
//event.stopEvent(); //try to stop showing menu, but no luck
//invoke the handler for menu item 1
//try to get at handler for menuitem programmatically
//theButton.menu.items.getAt(0).???
//i'd settle for hard-coding the function
//alert('foo');
}
});
答案 0 :(得分:1)
在这种情况下,您应该使用拆分按钮:
只有在单击箭头部分时才会显示菜单。当您单击按钮部分时,它将触发按钮处理程序而不显示菜单。