views:

254

answers:

1

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 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!

A: 

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.

Michael B
Well, the problem remains that i want the onClick to happen when i select the menu item. The evt.target is the menuItem itself and the enclosing widget is the menu... neither of which give me any way to get to the node that was click (that i know of)...
Dfowj
The node that's clicked will be an internal node from the MenuItem template, so you may not get what you expect. However, you might choose to dojo.connect to the 'onclick' DOM event (N.B. not 'onClick' which is a widget method) instead so you have the event to inspect?You might need to link to an example of this grid that you've described as I can't quite picture it.
Michael B