0
我有一个jsTree,用下面的代码推出:数据JsTree开放节点编程,数据源是JSON/AJAX
$(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
}
});
});
来源是JSON,通过AJAX getted。我有一个ID数组,当显示树时我需要扩展它。例如:
0
|_1
|_2
|_2.1
|_2.2
|_2.2.1
|_2.2.1.1
我的清单是['0', '2','2.2', '2.2.1']
。
我试过下面的代码(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);
});
});
节点使用id = 0打开成功地,但ID = 2没有打开,因为它,当我打开ID = 0仍然没有加载节点。
如何连续呼叫open_node
打开我的情况下的所有节点?
P.S.我找到了相似的答案/解决方案对here,但我不明白代码,解决方案没有帮助。