I have created a jstree and i have a problem with getting node by id of jstree. when i use get_node, i get an error:
TypeError: $(...).jstree.get_node is not a function
this is html code:
<div style="height: 75%; margin: 0; width: 100%;">
<div id="dashboardTree" style="border: 0; height: 99%; margin: 0; margin-top: 2px; overflow: auto; width: 99%;">
</div>
</div>
this is the javascript:
$(document).ready(function () {
initDashboardArchiveTree();//Initial tree
var node = $('#dashboardTree').jstree(true).get_node('1')//get that error
});
How to get node by id in jsTree?What's wrong with this code?
Try this:
var node = $('#dashboardTree').jstree(true).get_node('1, true')
New addition: true
OR
Change this:
var node = $('#dashboardTree').jstree(true).get_node('//something')
To this:
var node = $('#dashboardTree').jstree(true).find('//something');
Get the JSON of the parent and find the children.
Read the documentation on jstree/JSON.
To get the node use this:$('#dashboardTree').jstree(true).get_node('1');
If you need the actual DOM node, use this:
$('#dashboardTree').jstree(true).get_node('1', true);
But only invoke this once the tree is ready:
$('#dashboardTree').on('ready.jstree', function (e, data) {
var node = data.instance.get_node('1');
})
initDashboardArchiveTree(); //Initial tree
should help this one:
.on("hover_node.jstree", function (e, data) {
let node_id = data.node.id
let block = data.instance.get_node(node_id, true)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With