问题
I want to retrieve the parent of the child node
without clicking on the tree
..
data.inst._get_parent(data.rslt.obj).attr("id");
Above command give me the immediate parent when we click on the child nodes
.
Is there a way to get the parent node
without clicking on the child node
.
Regards, Praque M
回答1:
It seems the "data.inst" was renamed in newer versions to "data.instance". This made tracking down the solution difficult
data.instance.get_parent(data.node)
returns the string ID of the parent (much unexpected for me). To get the parent I had to call data.instance.get_node()
on the string ID.
data.instance.get_parent(data.node)
is also accessible thru data.node.parent.
Example:
$('#MaterialCollectionTree').on('activate_node.jstree', function(e, data) {
if(data.instance.is_leaf(data.node)) {
alert("Leaf: " + data.node.text);
alert("Parent: " + data.instance.get_node(data.node.parent).text);
}
});
回答2:
It is a bit more complex then that
parent_node = $.jstree._reference('#tree_id')._get_parent(n);
The variable parent_node is a jquery object so the command
parent_node.attr("something");
is the same as
$("#parent_node_id").attr("something");
来源:https://stackoverflow.com/questions/12914841/get-the-immediate-parent-of-child-node-in-jstree