递归遍历数据方法

时间:2021-07-01 16:42:14   收藏:0   阅读:0
    changeData (data) {
      const arr = []
      if (data.length !== 0) {
        data.forEach(item => {
          const obj = {}
          obj.id = item.path
          obj.label = item.name
          if (item.children.length >= 1) {
            obj.children = this.changeData(item.children)
          }
          arr.push(obj)
        })
      }

      return arr
    }

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!