When the parent node ztree loaded asynchronously checked automatically check all child nodes

Key Code:

//选择样本模板树
    var model_sample_ztree, model_sample_zNode;
    var modelsample_setting = {
            async: {
                enable: true,
                url:"admin/sample/modelSampleList",
                autoParam:["id","level=lv"]
            },
            check:{
                enable:true,
                chkboxType: {"Y":"ps", "N":"ps"}
            },
            data:{
                 simpleData : {
                        enable : true,
                        idKey : "id", //id编号命名 默认
                        pIdKey : "pid",// Default Name Parent id number
                        rootPId: 0 // root parent node for correcting data, i.e., the attribute value specified pIdKey  
                    }  
            },
            The callback: {    
                onAsyncSuccess: zTreeOnAsyncSuccess, // tree loaded successfully callback function
            }
    };

Loaded successfully callback function

/**
	* 加载成功的回调函数 
	* 树第一次加载成功则强制异步加载子节点
	* 展开其下面的子节点
	*/
	function zTreeOnAsyncSuccess(){
		//防止数据量过大,延迟加载
		 setTimeout(function(){		
		    var treeObj =  $.fn.zTree.getZTreeObj("ztree_modelsample");
		    var rootNodes = treeObj.transformToArray(treeObj.getNodes());
		    //循环判断该节点是否已加载子节点,是则进入下一次循环,否则加载子节点,确保加载子节点只加载一次,若加载多次会影响效率
		    for(var i=0; i<rootNodes.length; i++){
		        if(rootNodes[i].zAsync == false)
		            treeObj.reAsyncChildNodes(rootNodes[i], "refresh",true);    
		        else continue;
		    }
		  },1000);
	}

 

Guess you like

Origin blog.csdn.net/weixin_42656571/article/details/90770497