简体   繁体   中英

How to attach dijit/menu to a node without using id's?

According to the Dojo documentation for dijit/menu you can attach a menu to a node by specifying the id's of the node. Like in their example

  require([
  "dijit/Menu",
  "dijit/MenuItem",
  "dijit/CheckedMenuItem",
  "dijit/MenuSeparator",
  "dijit/PopupMenuItem",
  "dojo/domReady!"
  ], function(Menu, MenuItem, CheckedMenuItem, MenuSeparator, PopupMenuItem){

    var pMenu;
    pMenu = new Menu({
        targetNodeIds: ["progmenu"]
    });
    ...
    ...
    pMenu.startup();
  });

Node

<span id="progmenu">Right click me to get a menu</span>

However I cannot use Id's in my project. I need to use attach points. How can I attach a menu to a node by attach point instead?

Most places in Dojo where you can specify the id of a DOM node, you can specify the node itself as an alternative, assuming you can get a reference to it (as is the case with the attach point).

If the progmenu attach point refers to a widget, point at the widget's domNode.

pMenu = new Menu({
    targetNodeIds: [this.progmenu.domNode]
});

If the attach point is a DOM node, use attach point directly, or whatever variable contains a reference to the node.

pMenu = new Menu({
    targetNodeIds: [this.progmenu]
});

Another option is to use dijit/Menu .bindDomNode, using the same tricks to get to the node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM