如何在jsTree中获取所选节点的ID? [英] How do I get the id of the selected node in jsTree?
本文介绍了如何在jsTree中获取所选节点的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 jsTree 中获取所选节点的ID?
How can I get the id of the selected node in a jsTree?
function createNewNode() {
alert('test');
var tree = $.tree.reference("#basic_html");
selectedNodeId = xxxxxxxxx; //insert instruction to get id here
tree.create({ data : "New Node Name" }, selectedNodeId);
}
推荐答案
jsTree中的节点基本上是包裹的列出项目。这将为您提供第一个参考。
Nodes in jsTree are essentially wrapped list items. This will get you a reference to the first one.
var n = $.tree.focused().get_node('li:eq(0)')
您可以替换 $。tree.focused ()
如果你有对树的引用。
You can replace $.tree.focused()
if you have a reference to the tree.
要获取id,请取第一个匹配的元素
To get the id, take the first matched element
if (n.length)
id = n[0].id
或者您可以使用jQuery attr函数,该函数适用于集合中的第一个元素
or you can use the jQuery attr function, which works on the first element in the set
id = n.attr('id');
这篇关于如何在jsTree中获取所选节点的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文