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,但我不明白代碼,解決方案沒有幫助。