美文网首页
递归修改组织树的key

递归修改组织树的key

作者: 我没叫阿 | 来源:发表于2021-08-05 13:52 被阅读0次
  mapTree(org) {
    console.log(org);
    
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    return {
      // 分别将我们查询出来的值做出改变他的key
      title: org.menuName,
      key: org.menuId,
      id: org.menuId,
      path: org.path,
      
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map((i) => this.mapTree(i)) : [],
    };
  }

 const newTree = res.body.map((org) => this.mapTree(org))  // res.body => 你后台返回的数据

console.log(newTree)

相关文章

网友评论

      本文标题:递归修改组织树的key

      本文链接:https://www.haomeiwen.com/subject/jjumvltx.html