js数据转树形结构

    dataTOTree (data,val) {
      const map = {};
      data.forEach((item) => {
          map[item.currentNode] = item;
      });
      data.forEach((item) => {
          const parent = map[item.parentNode];
          if (parent) {
              (parent.children || (parent.children = [])).push(item);
          } else {
              val.push(item);
          }
      });
    }

 

posted @ 2020-12-26 10:43  林荼  阅读(681)  评论(0编辑  收藏  举报