First, realize the function

1, Ztree tree menu control to expand to any node implementation method

Supports regular expression matching without expanding certain specified nodes: juejin.cn/post/695681…

Two, code implementation

Ztree.init (.fn.ztree.init (.fn.ztree.init ((“#tree”)), setting, zTreeNodes); Created, which will not be described here.

// Expand all ztree nodes (b-(true:ztree- object; False: tree nodes),childnodes- childnodes or ztree objects,l- which level to expand to)
function showztreemenuNum(b,childnodes,l) {
	if(b){
		var rootnodes = zTreeObj.getNodes();
		showztreemenuNum(false,rootnodes,l);/ / recursion
	}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);/ / recursion}}}}Copy the code

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 : { // Set the data
			simpleData : {
				enable : true.idKey : "id".pIdKey : "pid".rootPId : null}},view : { // View Settings
			showIcon : true.showLine : true,},callback : {
			/* Tree asynchronously loaded after successful operation */
 
			onAsyncSuccess :function(){
				//zTreeObj.expandAll(true);
				showztreemenuNum(true,zTreeObj,3); }}};Copy the code