1、创建一个格式化文件formatTreeList.js
const formatTreeList = (list) => {
list.map((item) => {
item.title = item.name;
item.key = item.coder;
if (item['children']) {
item.children = formatTreeList(item.children);
}
return item;
});
return list;
};
export { formatTreeList };
2、在tree控件中直接赋值
const queryMaterialFlowTree = () => {
QueryMaterialFlowTree()
.then((response) => {
setMaterialFlowTree(formatTreeList(response.data.content));
})
.catch((error) => {});
};
<Tree
showLine={true}
showIcon={true}
treeData={materialFlowTree}
/>