如何在jsTree中获取所选节点的id
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);
}发布于 2010-04-06 22:28:17
jsTree中的节点本质上是包装的列表项。这将为您提供对第一个的引用。
var n = $.tree.focused().get_node('li:eq(0)')如果您有对树的引用,则可以替换$.tree.focused()。
要获取id,请获取第一个匹配的元素
if (n.length)
id = n[0].id或者可以使用jQuery attr函数,该函数作用于集合中的第一个元素
id = n.attr('id');发布于 2011-07-13 11:10:57
由于无法使用harpo的解决方案,并且不愿意使用Olivier的解决方案,因为它使用内部jsTree函数,所以我想出了一种不同的方法。
$('#tree').jstree('get_selected').attr('id')就这么简单。get_selected函数返回选定列表项的数组。如果对该数组执行.attr,jQuery将查看列表中第一项。如果您需要多个选择的ID,则将其视为数组。
发布于 2015-07-10 01:08:05
在jstree版本的3.1.1中,您可以直接从get_selected获取
$("#<your tree container's id>").jstree("get_selected")https://stackoverflow.com/questions/2585502
复制相似问题