我将这样的数据存储在商店中:
{id:"r1",name:"Rule1",data1:"InTo1",data2:"RuJa1",data3:"IO1",data4:"TS1", parent:"r0"},
{id:"r2",name:"Rule2",data1:"InTo2",data2:"RuJa2",data3:"IO2",data4:"TS2", parent:"r0"},
我用它构建了一棵树,现在当我在树节点(“ Rule1”)上单击“鼠标左键”时,我尝试获取ID(“ r1”)。
是否可以在树节点上通过简单的“左键单击”(而不是通过菜单)获得ID?
我的树:
var tree = new Tree({
model: myModel,
showRoot: true,
openOnClick: false,
id:"tree"
});
我的“左键单击功能”:
dojo.connect(tree, "onClick", function(item){
// Here I want to get the ID
});
This is my tree
最佳答案
问题解决了!!
用简单的代码:
var getObj = dijit.byId("tree").get("selectedItem");
您将在商店中得到对象。
现在,您可以轻松显示所有属性。
例如:
console.log(getObj.id)console:
"r1"
(when you click on Rule1).The properties will change when you click on another tree-node (Rule2,Rule3..)
Function:
dojo.connect(tree, "onClick", function(item){
var getObj =dijit.byId("tree").get("selectedItem");
console.log(getObj);
谢谢!