jsTree在ajax调用中加载子元素的子元素

时间:2015-10-16 12:43:52

标签: javascript jquery ajax jstree

我正在尝试在jsTree上加载带有ajax的子节点。我可以使用回调方法加载单击节点的子节点。但是我想在回调中加载多个级别。

示例:

           [{"text" : "Child 2", "id" : "2", "children" : true}, 
            {"text" : "Child 3", "id" : "3", "children" : true}, 
            {"text" : "Parent 4", "id" : "4", "children" : true},
            {"text" : "Child 5", "id" : "5", "parent": "4", "children" : true}]

看来我想加载一个嵌套节点。这似乎不可能。我创造了一个小提琴来说明。

jsfiddle

1 个答案:

答案 0 :(得分:0)

基于Livius回答。

           [{"text" : "Child 2", "id" : "2", "children" :[{"text" : "Grand Child 2", "id" : "12"}]}, 
            {"text" : "Child 3", "id" : "3", "children" :[{"text" : "Grand Child 3", "id" : "13"}]}, 
            {"text" : "Parent 4", "id" : "4", "children" :[{"text" : "Grand Child 4", "id" : "14"}]},
            {"text" : "Child 5", "id" : "5", "children" :[{"text" : "Grand Child 5", "id" : "15"}]}]

当我们使用嵌套子结构而不是父子id结构(在jsTree.com上命名的替代结构)时,它正在工作。

Working Fiddle