zoukankan      html  css  js  c++  java
  • 异步记载树默认展开

    异步记载树默认展开:
            1、页面进来加载方法:expandAll();
            2、异步加载回调函数:onAsyncSuccess: zTreeOnAsyncSuccess
            3、然后加入下面内容:
            var curStatus = "init", curAsyncCount = 0, asyncForAll = false,goAsync = false;
            function beforeAsync() {
                curAsyncCount++;
            }
            function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
                curAsyncCount--;
                if (curStatus == "expand") {
                    expandNodes(treeNode.children);
                } else if (curStatus == "async") {
                    asyncNodes(treeNode.children);
                }
    
                if (curAsyncCount <= 0) {
                    if (curStatus != "init" && curStatus != "") {
                        asyncForAll = true;
                    }
                    curStatus = "";
                }
            }
            function expandAll() {
                if (!check()) {
                    return;
                }
                var zTree = $.fn.zTree.getZTreeObj("fitTypeTree");
                if (asyncForAll) {
                    zTree.expandAll(true);
                } else {
                    expandNodes(zTree.getNodes());
                    if (!goAsync) {
                        curStatus = "";
                    }
                }
            }
            function check() {
                if (curAsyncCount > 0) {
                    return false;
                }
                return true;
            }
            function expandNodes(nodes) {
                if (!nodes) return;
                curStatus = "expand";
                var zTree = $.fn.zTree.getZTreeObj("fitTypeTree");
                for (var i=0, l=nodes.length; i<l; i++) {
                    zTree.expandNode(nodes[i], true, false, false);
                    if (nodes[i].isParent && nodes[i].zAsync) {
                        expandNodes(nodes[i].children);
                    } else {
                        goAsync = true;
                    }
                }
            }
            function asyncNodes(nodes) {
                if (!nodes) return;
                curStatus = "async";
                var zTree = $.fn.zTree.getZTreeObj("fitTypeTree");
                for (var i=0, l=nodes.length; i<l; i++) {
                    if (nodes[i].isParent && nodes[i].zAsync) {
                        asyncNodes(nodes[i].children);
                    } else {
                        goAsync = true;
                        zTree.reAsyncChildNodes(nodes[i], "refresh", true);
                    }
                }
            }
  • 相关阅读:
    MT7601 AP模式移植
    dhcp server 移植记录
    MT7601 WG209模块驱动移植,并连接路由器
    git 忽略文件
    关于中文--Unicode之间互相转换流程的说明
    将文字拆成拼音得到首字母(返回多音字)
    Javascript 汉字转首字母的拼音 js文件(支持多音字的选择)
    如何使用netstat –ano|findstr “port”命令?
    notepad++如何修改主题
    Notepad++ 更换主题
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/6586484.html
Copyright © 2011-2022 走看看