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

 这个世界我看不懂2011_595 发布于 2022-12-27 12:14

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

$(function () {
    // Create the tree inside the 
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!" }, }) });

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

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

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

1 个回答
  • 我想你可以使用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);
                });
            }
        }
    }
    

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

    2022-12-27 12:16 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有