//树菜单回显(多级) changeDetSelect(key, treeData) { let arr = []; // 在递归时操作的数组 let returnArr = []; // 存放结果的数组 let depth = 0; // 定义全局层级 // 定义递归函数 function childrenEach(childrenData, depthN) { for (var j = 0; j < childrenData.length; j++) { depth = depthN; // 将执行的层级赋值 到 全局层级 arr[depthN] = childrenData[j].id; if (childrenData[j].id == key) { returnArr = arr.slice(0, depthN + 1); //将目前匹配的数组,截断并保存到结果数组, break; } else { if (childrenData[j].children) { depth++; childrenEach(childrenData[j].children, depth); } } } return returnArr; } return childrenEach(treeData, depth); },
标签:childrenData,arr,vue,回显,depthN,childrenEach,depth,树形 From: https://www.cnblogs.com/porter/p/17104974.html