简体   繁体   English

如何在不使用ID的情况下将dijit /菜单附加到节点?

[英]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. 根据Dijit / menu的Dojo文档,您可以通过指定节点的ID将菜单附加到节点。 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. 但是,我不能在项目中使用ID。 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). 在Dojo中,您可以指定DOM节点的ID的大多数地方,可以指定该节点本身作为替代,假设您可以获取对该节点的引用(如附加点的情况)。

If the progmenu attach point refers to a widget, point at the widget's domNode. 如果程序附加点指向小部件,请指向小部件的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. 如果连接点是DOM节点,请直接使用连接点,或任何包含对该节点的引用的变量。

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

Another option is to use dijit/Menu .bindDomNode, using the same tricks to get to the node. 另一个选择是使用dijit / Menu .bindDomNode,并使用相同的技巧到达节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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