您将不得不覆盖菜单onMouseOver
和onClick
方法以防止菜单被扩展。您还需要在菜单中添加 ignoreParentClicks 配置。
它看起来像:
Ext.define('Ext.o.menu.Menu', {
override : 'Ext.menu.Menu',
onClick: function(e) {
var me = this,
type = e.type,
item,
clickResult,
iskeyEvent = type === 'keydown';
if (me.disabled) {
e.stopEvent();
return;
}
item = me.getItemFromEvent(e);
if (item && item.isMenuItem) {
if (!item.menu || !me.ignoreParentClicks) {
clickResult = item.onClick(e);
} else {
e.stopEvent();
}
// SPACE and ENTER invokes the menu
if (item.menu && clickResult !== false) {
item.expandMenu(e, 0);
}
}
// Click event may be fired without an item, so we need a second check
if (!item || item.disabled) {
item = undefined;
}
me.fireEvent('click', me, item, e);
},
onMouseOver: function(e) {
var me = this,
fromEl = e.getRelatedTarget(),
mouseEnter = !me.el.contains(fromEl),
item = me.getItemFromEvent(e),
parentMenu = me.parentMenu,
ownerCmp = me.ownerCmp;
if (mouseEnter && parentMenu) {
parentMenu.setActiveItem(ownerCmp);
ownerCmp.cancelDeferHide();
parentMenu.mouseMonitor.mouseenter();
}
if (me.disabled) {
return;
}
// Do not activate the item if the mouseover was within the item, and it's already active
if (item) {
if (!item.containsFocus) {
item.focus();
}
// This will not be needed here!
//if (item.expandMenu) {
//item.expandMenu(e);
//}
}
if (mouseEnter) {
me.fireEvent('mouseenter', me, e);
}
me.fireEvent('mouseover', me, item, e);
}
});
检查这个小提琴:https ://fiddle.sencha.com/#fiddle/u1m