Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在dojo树中的右键单击上下文菜单上获取id?_Javascript_Tree_Contextmenu_Dojo - Fatal编程技术网

Javascript 如何在dojo树中的右键单击上下文菜单上获取id?

Javascript 如何在dojo树中的右键单击上下文菜单上获取id?,javascript,tree,contextmenu,dojo,Javascript,Tree,Contextmenu,Dojo,我想在上下文菜单上获得Dojo树的节点id 我正在Dojo做一棵这样的树。这是id-第一个参数 this.setData( [ { id: '5', name:'root' , type:'continent' }, { id: '6', name:'catalog 1', parent: '5' , type:'continent' }, { id: '7', name:'catalog 2', parent: '5' , type:'continent' },

我想在上下文菜单上获得Dojo树的节点id

我正在Dojo做一棵这样的树。这是id-第一个参数

 this.setData(
            [
{ id: '5', name:'root' , type:'continent' }, 
{ id: '6', name:'catalog 1', parent: '5' , type:'continent' }, 
{ id: '7', name:'catalog 2', parent: '5' , type:'continent' }, 
{ id: '8', name:'catalog 2.1', parent: '7' , type:'continent' }, 
{ id: '9', name:'child Catalog', parent: '8' , type:'continent' }, 
{ id: '10', name:'catalog 4', parent: '5' , type:'continent' } ]); 
这是我的树和菜单初始化函数。
因此,当我用树上的右键单击时,有一个带有按钮的上下文菜单。当我单击该按钮时,它会触发onClick功能。我想接收该id

     <script>
        function createMyTree()
        {
            var tree = new dijit.Tree({
                                        model: myModel,
                                        id: 'contextMenu'
                                        });
            tree.placeAt("myTree", "last");
            tree.startup();


            pMenu = new dijit.Menu({
                targetNodeIds:["contextMenu"]
            });

            pMenu.addChild(new dijit.MenuItem({
                label:"Delete",
                iconClass:"dijitEditorIcon dijitEditorIconDelete",
                onClick: function(){
                    /// HERE I WANT MY id
                }
            }));

            pMenu.startup();
}

函数createMyTree()
{
var tree=新的dijit.tree({
型号:myModel,
id:“上下文菜单”
});
tree.placeAt(“myTree”、“last”);
tree.startup();
pMenu=新的dijit.菜单({
targetNodeId:[“上下文菜单”]
});
pMenu.addChild(新的dijit.MenuItem({
标签:“删除”,
iconClass:“dijitEditorIcon dijitEditorIconDelete”,
onClick:function(){
///这是我的身份证
}
}));
pMenu.startup();
}

我该怎么做呢?

我以前没有使用过dojo,但我认为您应该在onclick上使用事件。从中,您可以获得
目标
相关目标
,并使用
按钮
属性检查它(按下的鼠标按钮类型;可能为2)

如果没有提供有效的元素,您可以从
event.screenX
event.screenY
获取有效元素。

我找到了它。。 谢谢各位。如果您有更好的建议,请分享。:)


选择器:“.dijitTreeNode”在菜单配置选项中。

您能创建一个最低限度的选项吗?关键是dojo从输入生成DOM。因此,即使当我阅读这个HTML(生成的树节点代码)时,我也看不到这个ID——它是被指定的,例如,没有包含它的属性。所以情况很糟糕。。。我必须使用一些Dojo方法,但我不知道witch,文档中没有提到这一点……是的,当然——代码在我的问题中——有两部分。第一个是json数据(这里有我想要的ID——第一个参数)。第二个是构建该树的javascript函数。你还需要一些吗?@DonAngeloAnnoni对不起,我在问一个正在运行的演示。也许可以从正在运行的演示中找到一些东西。
   var selectedObject = tree.get("selectedItems")[0];
   console.log("the id what I need", selectedObject.id);