我在同一页面上有2个相同的dynatrees,如同js fiddle http://jsfiddle.net/37ppf/3/所示。
$("#tree1").dynatree({
onSelect : function(select,node){},
checkbox: true,
children: [
{title: "Item 1",key:"1"},
{title: "Folder 2", isFolder: true, key:"2",
children: [
{title: "Sub-item 2.1", },
{title: "Sub-item 2.2", }
]
},
{title: "Item 3",key:"5"}
]
});
$("#tree2").dynatree({
onSelect : function(select,node){},
checkbox: true,
children: [
{title: "Item 1",key:"1"},
{title: "Folder 2", isFolder: true, key:"2",
children: [
{title: "Sub-item 2.1", },
{title: "Sub-item 2.2", }
]
},
{title: "Item 3",key:"5"}
]
});
<div id="tree1"> </div>
<div id="tree2"> </div>
现在,当用户选择任何dynatree中的任何节点时,我想获取div id
,其中用户选择了该节点的树已加载。如果用户从第一棵树中选择,我想要获取输出为tree1
(div id),如果从第二个树中选择一个节点,我想获得tree2
。这可能吗。我试过了
$(this).closest(".dynatree-container").parent("div").attr("id")
但它的未定义。