antd-mobile
Version:
<img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*hjjDS5Yy-ooAAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />
16 lines (15 loc) • 372 B
JavaScript
// 找到树的深度
export function getTreeDeep(treeData, childrenName = 'children') {
const walker = tree => {
let deep = 0;
tree.forEach(item => {
if (item[childrenName]) {
deep = Math.max(deep, walker(item[childrenName]) + 1);
} else {
deep = Math.max(deep, 1);
}
});
return deep;
};
return walker(treeData);
}