// this.handleSuperiorAndSubordinateTree(response.data); 方法调用
handleSuperiorAndSubordinateTree(data) {
// 创建一个空对象用于存储节点数据
const nodes = {};
// 遍历数据,将每个节点按照id存储到nodes对象中
data.forEach((item) => {
nodes[item.zid] = {
id: item.zid, //子集id
nr: item.nr, //字段名称
zt: item.zt,
kssj: item.kssj,
jssj: item.jssj,
ms: item.ms,
parentId: item.parentId, //父级id
children: [], //子集存储
};
});
console.log(data,'data')
// 遍历nodes对象,将每个节点添加到其父节点的children数组中
Object.values(nodes).forEach((node) => {
if (node.parentId !== 0) {
const parentNode = nodes[node.parentId];
if (parentNode) {
parentNode.children.push(node);
}
}
});
console.log(this.tableData = [Object.values(nodes).find((node) => node.parentId === 0)],'====')
return (this.tableData = [Object.values(nodes).find((node) => node.parentId === 0)]
);
},
09-25
1406
11-28
12-26
337
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交