0

我想在上下文菜单单击时获取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();
}

我怎样才能做到这一点?

4

3 回答 3

0

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

   var selectedObject = tree.get("selectedItems")[0];
   console.log("the id what I need", selectedObject.id);
于 2013-05-14T08:01:03.507 回答
0

I haven't used dojo before, but I think you should use the contextmeu event over onclick. From that you can get the target or relatedTarget and checking it with button property (the type of mouse button pressed; probably 2).

If that doesn't gives you a valid element, you can use document.elementFromPoint(x,y) from the event.screenX and event.screenY to get the valid element.

于 2013-05-13T15:18:42.223 回答
0

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

于 2014-07-22T09:10:20.310 回答