The realization method of ztree tree menu control expansion to arbitrary nodes

Improved version, adding regular matching mechanism

Ztree expands to the specified level, and supports regular expression matching mode to not expand certain specified nodes

One, realize the function

1. The realization method of ztree tree menu control to expand to any number of nodes

Two, code implementation

 

//展开全部ztree树节点(b-(true:ztree-对象;false:树节点),childnodes-子节点或ztree对象,l-要展开到哪个层级)
function showztreemenuNum(b,childnodes,l) {
	if(b){
		var rootnodes = zTreeObj.getNodes();
		showztreemenuNum(false,rootnodes,l);//递归
	}else{
		var len=-1;
		if(!isNull(childnodes)&&!isNull((len=childnodes.length))&&len>0){
			if(l<childnodes[0].level){
				return;
			}
			for (var i = 0; i < len; i++) {
				zTreeObj.expandNode(childnodes[i], true, false, false, true);
				var child=childnodes[i].children;
				showztreemenuNum(false,child,l);//递归
			}
		}
	}
}

 

 

 

 

 

Three, use examples

 

ztreeSetting = {
		async : {
			enable : true,
			url:'getTreeList',
			type : "post",
			contentType : "application/json",
			autoParam : [ "id", "pid" ],
			otherParam : [ "requestType", "init" ]
		},
		expandSpeed : "fast",
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType: { "Y": "ps", "N": "ps" }
		},
		data : { // 数据的设置
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "pid",
				rootPId : null
			}
		},
		view : { // 视图的设置
			showIcon : true,
			showLine : true,

		},
		callback : {
			/*树异步加载成功后操作*/

			onAsyncSuccess :function(){
				//zTreeObj.expandAll(true);
				showztreemenuNum(true,zTreeObj,3);
				
			}
		}
	};

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/eguid/article/details/78423183