original data format:
let arr = [
{
"id": 28,
"name": "()",
"email": "zhanmoumou@1.cn",
"children": [
{
"id": 25,
"email": "@1.cn",
"name": "",
"children": [
{
"sale": [
{
"id": 48,
"name": "SYS",
"email": "services@1.cn"
},
{
"id": 98,
"name": "2",
"email": "ceshi_account_two@1.cn"
}
],
"operation": [
{
"id": 27,
"name": "",
"email": "cui@1.cn"
},
{
"id": 88,
"name": "",
"email": "lilu@1.cn"
},
],
"sale_manager": [
{
"id": 15,
"name": "",
"email": "yuanxiao@1.cn"
},
{
"id": 87,
"name": "",
"email": "ceshi@1.cn"
}
]
}
]
},
{
"id": null,
"email": null,
"name": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
]
},
{
"id": null,
"name": "()",
"email": null,
"children": [
{
"id": null,
"email": null,
"name": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
},
{
"id": null,
"email": null,
"name": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
]
},
{
"id": null,
"name": "()",
"email": null,
"children": [
{
"id": null,
"email": null,
"name": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
},
{
"id": null,
"email": null,
"name": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
]
}
]
converted data format:
let brr = [
{
"key": 28,
"name": "()",
"email": "zhanmoumou@1.cn",
"value": "()",
"children": [
{
"key": 25,
"email": "hemoumou@1.cn",
"name": "",
"value": "",
"children": [
{
[
{
"key": 48,
"name": "SYS",
"value": "SYS",
"email": "services@1.cn",
},
{
"key": 98,
"name": "2",
"value": "2",
"email": "ceshi_account_two@1.cn"
},
],
[
{
"key": 27,
"name": "",
"value": "",
"email": "cuimoumou@1.cn"
},
{
"key": 88,
"name": "",
"value": "",
"email": "lilu@1.cn"
},
],
[
{
"key": 15,
"name": "",
"email": "yuanxiao@y1.cn"
},
{
"key": 87,
"name": "",
"email": "ceshi@1.cn"
}
]
}
]
},
{
"key": null,
"email": null,
"name": "",
"value": "",
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
],
},
{
"key": null,
"name": "()",
"value": "()"
"email": null,
"children": [
{
"key": null,
"email": null,
"name": "",
"value": "",
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
},
{
"key": null,
"email": null,
"name": "",
"value": "",
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
]
},
{
"key": null,
"name": "()",
"value": "()",
"email": null,
"children": [
{
"key": null,
"email": null,
"name": null,
"value": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
},
{
"key": null,
"email": null,
"name": null,
"value": null,
"children": [
{
"sale": [],
"operation": [],
"sale_manager": []
}
]
}
]
},
];
I encapsulated a function processing,
function getTreeData (tree) {
let getData = [];
tree.map((item, key) => {
let obj = {}
obj = {
"key": item.id,
"label": item.name || "",
"value": item.name || "",
"email": item.email,
}
if (item.children) {
getData.push(Object.assign(
{"children" :getTreeData(item.children)}, obj))
} else {
getData.push(obj);
}
})
return getData
}
but because the data structure of the innermost layer is different, the innermost layer does not handle it correctly.