How to get node by ID in Jstree

I created jstree and I have a problem getting node by id jstree. when i use get_node i get an error:

TypeError: $ (...). jstree.get_node is not a function

this is the 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 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 happened to this code?

+4
source share
2 answers

Try the following:

var node = $('#dashboardTree').jstree(true).get_node('1, true')

New addition: true

OR

Change this:

var node = $('#dashboardTree').jstree(true).get_node('//something')

For this:

var node = $('#dashboardTree').jstree(true).find('//something');

Get the parent JSON and find the children.

Read the jstree / JSON documentation .

+7
source

To get 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 just call it as soon as the tree is ready:

$('#dashboardTree').on('ready.jstree', function (e, data) {
  var node = data.instance.get_node('1');
})
initDashboardArchiveTree(); //Initial tree
+4
source

Source: https://habr.com/ru/post/1598982/


All Articles