使用子菜单单击未在MenuItem上触发的事件

时间:2021-09-08 05:41:01

In my nw.js app I have a menubar with a 'Parent' menuitem. 'Parent' has both a click event and a submenu. I noticed the click event on parent does not trigger when there is a submenu. Is there any way to capture the click event on the parent menuitem of the submenu? Or is this simply expected behavior?

在我的nw.js应用程序中,我有一个带有'Parent'菜单项的菜单栏。 'Parent'同时包含点击事件和子菜单。我注意到,当存在子菜单时,父级上的click事件不会触发。有没有办法捕获子菜单的父菜单项上的click事件?或者这只是预期的行为?

    var menubar = new window.gui.Menu({ type: 'menubar' });
    var fileMenu = new window.gui.Menu();
    fileMenu.append(new window.gui.MenuItem({
        label: 'New',
        click: function() {
            window.alert("New");
        }
    }));
    fileMenu.append(new window.gui.MenuItem({
        label: 'Open',
        click: function() {
            window.alert("Open");
        }
    }));
    menubar.append(new window.gui.MenuItem({
        label: 'Parent',
        submenu: fileMenu,
        click: function() {
            window.alert("Does not fire when submenu set");
        }
    }));
    window.win.menu = menubar;

1 个解决方案

#1


This is expected behavior. In other desktop applications, you also don't see a menu item without a submenu attached to it...

这是预期的行为。在其他桌面应用程序中,您也没有看到没有附加子菜单的菜单项...

#1


This is expected behavior. In other desktop applications, you also don't see a menu item without a submenu attached to it...

这是预期的行为。在其他桌面应用程序中,您也没有看到没有附加子菜单的菜单项...