js递归树,修改树的key

mapTree (org) {
const haveChildren = Array.isArray(org.children) && org.children.length > 0;
return {
     //分别将我们查询出来的值做出改变他的key
title: org.groupName,
label: org.groupName,
value: org.id,
data: {...org},
        //判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
        children: haveChildren ? org.children.map(i => this.mapTree(i)) : []
};
},

getOrgTree () {
this.$Request.get('api/groups/tree', {}).then(res => {
console.log(res);
if (res && res.code === 0) {
if (Array.isArray(res.data)) {
this.orgTree = res.data.map(org => this.mapTree(org));
this.orgTree.push({
title: '无',
label: '无',
value: 0,
})
}
}
});
},
原文地址:https://www.cnblogs.com/boonook/p/9353328.html