I've got a jsTree, launched with following code:
$(function () {
var grid = $('#group-tree');
grid
.jstree({
core: {
data: {
url: '<url to json source>',
data: function (node) {
return {'id': node.id};
}
},
'multiple': false,
'animation': false
}
});
});
Source of data is json, getted via ajax. I have an array of ids, which I need to expand when tree is showed. For example:
0
|_1
|_2
|_2.1
|_2.2
|_2.2.1
|_2.2.1.1
My list is ['0', '2','2.2', '2.2.1']
.
I've tried the following code (added after var grid = $('#group-tree');
):
grid.on('ready.jstree', function (e, data) {
// ids of nodes I need to expand
var nodeValues = ['0', '2','2.2', '2.2.1'];
nodeValues.forEach(function (item) {
$('#group-tree').jstree(true).open_node(item);
});
});
Node with id=0 opens succesfully, but id=2 not opened, because it's still not loaded when I open id=0 node.
How to successively call open_node
to open all nodes in my case?
P.S. I've found simular answer/solution pair here, but I don't understand the code, solution didn't helped.