vue 递归遍历数据

    function changeTree(val) {
      let arr = [];
      if (val.length !== 0) {
        val.forEach(item => {
          let obj = {};
          obj.id = item.path;
          obj.label = item.name;
          if (item.children.length >= 1) {
            obj.children = this.changeTree(item.children);
          }
          arr.push(obj);
        });
      }

      return arr;
    },
posted @ 2019-12-05 15:53  帖子搬运工  阅读(2366)  评论(0编辑  收藏  举报