JS递归树结构,修改树结构的属性值key和value

1,069 阅读1分钟
 const mapTree = org => {
      const haveChildren = Array.isArray(org.childList) && org.childList.length > 0;
      return {
        key : org.id,
        value : String(org.id),
        title: org.deptName,
        children:haveChildren ? org.childList.map(i => mapTree(i)) : [],
      }
    };
    let arr = []
    arr = treeData.map(org => mapTree(org) )