版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010996565/article/details/81840104
ztree展开全部节点
$jqueryTree(document).ready(function(){
queryMenuTree('0');
//为了避免数据流过大,采用延迟展开
setTimeout(function(){
expandAll();
},1000);
});
var curStatus = 'init', // 当前状态
curAsyncCount = 0, // 异步加载次数
goAsync = false; //异步
function expandAll(){
if(!check()){
return ;
}
var treeObj = $jqueryTree.fn.zTree.getZTreeObj("ztree");
expandNodes(treeObj.getNodes());
if(!goAsync){
curStatus = '';
}
}
function expandAll(){
if(!check()){
return ;
}
var treeObj = $jqueryTree.fn.zTree.getZTreeObj("ztree");
expandNodes(treeObj.getNodes());
if(!goAsync){
curStatus = '';
}
}
function expandNodes(nodes){
//如果nodes为null 则return
if(!nodes) return;
//将状态设置为expand
curStatus = 'expand';
//获取当前的树
var treeObj = $jqueryTree.fn.zTree.getZTreeObj("ztree");
//循环展开节点
for (var i = 0 ; i < nodes.length; i++){
treeObj.expandNode(nodes[i],true,false,false);
//递归 如果子节点的是父节点则进行递归操作
if(nodes[i].isParent && nodes[i].zAsync){
expandNodes(nodes[i].children);
} else {
goAsync = true;
}
}
}