方式一:
// -------------------------------------加载时展开所有节点
function expandAll() {
var zTree = $.fn.zTree.getZTreeObj("moduleTree");
expandNodes(zTree.getNodes());
}
function expandNodes(nodes) {
if (!nodes) return;
var zTree = $.fn.zTree.getZTreeObj("moduleTree");
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;
}
}
}
方式二:
// zTree加载时展开所有节点
function zTreeExpandAll(treeId,flag) {
expandFlag = flag ;
var treeObj = $.fn.zTree.getZTreeObj(treeId);
var nodes = treeObj.getNodesByFilter(function(node){ //自定义过滤条件
return ( node.isParent == true); //check_Child_State 用来判断是否有子节点,0表示有,-1表示无
});
if (nodes.length>0) {
$.each(nodes,function(key,value){
//[节点数据][展开/折叠][全部子孙点/当前节点][设置焦点][执行回调函数?]
treeObj.expandNode(value, expandFlag, true, false,false);
}) ;
}
}