开发者

Dojo Popup Menus - Connect a menu item event to multiple 'triggering' elements

开发者 https://www.devze.com 2023-01-01 08:15 出处:网络
What i have is a single dijit.Menu that contains the dijit.MenuItem objects with labels 1 - 9. It is connected to a sudoku like grid of 81 \'nodes\' (because there are so many, i dont bother with indi

What i have is a single dijit.Menu that contains the dijit.MenuItem objects with labels 1 - 9. It is connected to a sudoku like grid of 81 'nodes' (because there are so many, i dont bother with individual id's, i simply collect them with dojo.query('their-css-class-name')). This is the code i'm using inside of a widget to instantiate the context menu and its menu items.

    var contextMenu = new dijit.Menu({targetNodeIds:dojo.query(".sudokuNode"), leftClickToOpen:true});

    for(var i = 1; i <= 9; i++) {
        contextMenu.addChild(new dijit.MenuItem({
            label:i,
            onClick: function(evt) {
                //??
            }
        }));
    };

    contextMenu.startup();

What i'm trying to do is have the node that is clicked, and subsequently opens a popup/context menu, be filled with the value (1-9) selected from the context menu's MenuItems.

My problem is that i dont know how to "know" which of the 81 nodes was the one to fire the oncontextmenu开发者_JS百科 event, and i dont know how to reference that node inside the 'onClick' method declared in the menu item.

Any help demonstrating how to reference the calling node in that context would be appreciated! If this isn't enough information, let me know what else i can do to explain my problem!


evt.target should get you the node that was actually clicked. Depending on the structure, you may need to do some other navigation from there, or use dijit.getEnclosingWidget().

If the MenuItems allow the events to bubble (I'm not sure; haven't used it myself), you could connect to the onClick() method of the Menu, so you've only got the single event listener in play.

0

精彩评论

暂无评论...
验证码 换一张
取 消