getCurrentTreeDeep(treeData) {
let arr = [];
arr.push(treeData);
let depth = 0;
while (arr.length > 0) {
let temp = [];
for (let i = 0; i < arr.length; i++) {
temp.push(arr[i]);
}
arr = [];
for (let i = 0; i < temp.length; i++) {
if (temp[i].children && temp[i].children.length > 0) {
for (let j = 0; j < temp[i].children.length; j++) {
arr.push(temp[i].children[j]);
}
}
}
if (arr.length >= 0) {
depth++;
}
}
return depth;
}
判断当前树节点的深度
猜你喜欢
转载自blog.csdn.net/baidu_39009276/article/details/123544275
今日推荐
周排行