treeToFlat(tree, parentKey = null, result = []) {
for (let node of tree) {
const newNode = { ...node, parentId: parentKey };
result.push(newNode);
if (node.children && node.children.length > 0) {
this.treeToFlat(node.children, node.id, result);
}
delete newNode.children; // 删除节点的children属性
}
return result;
},
safeListToTree(items, parentId = null, currentDepth = 0) {
if (currentDepth >= 30) {
return []; // 达到最大深度,返回空数组
}
const rootItems = items.filter((item) => item.parentId === parentId);
rootItems.forEach((item) => {
item.children = this.safeListToTree(items, item.uuid, currentDepth + 1);
});
return rootItems;
},
2024-10-28
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前言:在项目中使用vue-antd的tree组件时,发现它的搜索功能没有达到我们项目的要求,所以将它的搜索功能优化...
- 前言:tree组件自定义slot,数据项需要手动添加scopedSlots。 一、绘制的页面如下: 二、组件代码 ...