Fancytree 延迟加载异常:断言失败:预期的子数组

Fancytree lazy load exception : assertion failed: expected array of children

我有一个现有的树,它基于 JSON 构建,具有 3 级层次结构。

根 -> ChildLevel1 -> ChildLevel2(懒惰=真)

上面的树数据在页面加载时作为源加载。,一切正常 point.Now - 在 childlevel2 上,我正在尝试动态填充子项:

lazyLoad: function (event, data) {              
                var json = "{children:[ {\"title\": \"Sub item\", \"lazy\": true }, {\"title\": \"Sub folder\", \"folder\": true, \"lazy\": true } ]}";
                data.result = json;
            }

我不断收到以下异常:

Uncaught Error: Fancytree assertion failed: expected array of children at Function.error (jquery-1.12.4.min.js:2) at _assert (jquery.fancytree.js:82) at jquery.fancytree.js:3242 at i (jquery-1.12.4.min.js:2) at Object.add [as done] (jquery-1.12.4.min.js:2) at Fancytree.nodeLoadChildren (jquery.fancytree.js:3229) at Fancytree._callHook (jquery.fancytree.js:2289) at FancytreeNode.load (jquery.fancytree.js:1229) at Fancytree.nodeSetExpanded (jquery.fancytree.js:3965) at Fancytree.nodeToggleExpanded (jquery.fancytree.js:4230)

您正在传递定义对象的 JSON 字符串,但插件需要 "array of children"。尝试:

lazyLoad: function (event, data) {              
  var res = [
    { title: "Sub item", lazy: true },
    { title: "Sub folder", folder: true, lazy: true }
    ];
  data.result = res;
}