0
点赞
收藏
分享

微信扫一扫

js,递归获取所有父级Id

独孤凌雪 2022-03-10 阅读 60
// 获取所有父级ID
  function  getActiveMenuId(path, arr, paths) {
        if (paths === undefined) {
            paths = []
        }
        if(arr){
          for (let i = 0; i < arr.length; i++) {
              const tmpPath = paths.concat()
              tmpPath.push(arr[i].id)
              if (path === arr[i].path) {
                  return tmpPath
              }
              if (arr[i].children !== null) {
                  const findResult = getActiveMenuId(path, arr[i].children, tmpPath)
                  if (findResult) {
                      return findResult
                  }
              }
          }
        }
    }
// 调用
getActiveMenuId(path,arr)
举报

相关推荐

0 条评论