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

jsTree load children of child elements in ajax call

我正在尝试在 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}]

看来我想加载一个嵌套节点。这似乎不可能。我创建了一个 fiddle 来说明。

jsfiddle

基于 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