需求:获取树结构的节点深度。

实现util.js:

// 获取节点深度 参数为树结构array
function getMaxFloor(treeData){
  let deep = 0;
  function eachData(data, index) {
    data.forEach(elem => {
       if (index > deep) {
          deep = index;
       }
       if (elem.children.length > 0) {
          eachData(elem.children, deep + 1);
        }
  }) }
  getMaxFloor(treeData, 1);
  return deep;
}

 

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
相关资源
相似解决方案