FancyTree在select上加载所有嵌套的子项

Mic*_*ews 4 javascript jquery fancytree

这是我的问题.我通过ajax使用复选框和延迟加载.但是,如果要检查父项而不扩展它,则不会加载任何子节点,因此不会检查它们.如何在父项下加载所有子节点和嵌套子节点,并在检查父节点时全部检查它们?谢谢,这就是我到目前为止所拥有的

$(function () {
    // Create the tree inside the <div id="tree"> element.
    $("#tree").fancytree({
        source: { url: "/Home/GetData", cache: true }
        , checkbox: true
        , icons: false
        , cache: true
        , lazyLoad: function (event, data) {
            var node = data.node;
            data.result = {
                url: "/Home/GetTreeViewData/" + node.key
                , data: { mode: "children", parent: node.key }
                , cache: true
            };
        }
        , selectMode: 3
        , select: function (event, data) { //here's where I need to load the children and any sub children for that node, if it has them, so they can be set to checked

        }
        , strings: {
            loading: "Grabbing places and events…",
            loadError: "Load error!"
        },
    })
});
Run Code Online (Sandbox Code Playgroud)

更新 我需要拉这些客户端的原因是因为这是一个将加载谷歌地图标记的树视图.所以,如果我有一个像这样的结构

Parent1
- > child1-1
- > - > child1-1-1
- > child1-2

所有这些子节点加载延迟.但是,如果要检查父节点1,那么我需要为所有这些子节点加载标记.这就是为什么我正在寻找一种递归方式让所有孩子都能得到的方法.因为要跟踪已添加/未添加的标记真的很难,如果我不只是加载树视图项并选中复选框.合理?

And*_* M. 7

我想你可以使用select事件:

select: function(event, data) {
    var node = data.node;

    if (node.isSelected()) {
        if (node.isUndefined()) {
            // Load and select all child nodes
            node.load().done(function() {
                node.visit(function(childNode) {
                    childNode.setSelected(true);
                });
            });
        } else {
            // Select all child nodes
            node.visit(function(childNode) {
                childNode.setSelected(true);
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这样,如果尚未加载子节点,则在此之后将加载并选择它们.