REVIEW 代码预览(PreviewCode)

This commit is contained in:
YunaiV
2023-03-29 22:25:53 +08:00
parent b1e74a1d05
commit e6dac1ebda
3 changed files with 57 additions and 31 deletions

View File

@ -276,7 +276,7 @@ export const handleTree = (data: any[], id?: string, parentId?: string, children
export const handleTree2 = (data, id, parentId, children, rootId) => {
id = id || 'id'
parentId = parentId || 'parentId'
children = children || 'children'
// children = children || 'children'
rootId =
rootId ||
Math.min(
@ -285,16 +285,16 @@ export const handleTree2 = (data, id, parentId, children, rootId) => {
})
) ||
0
//对源数据深度克隆
// 对源数据深度克隆
const cloneData = JSON.parse(JSON.stringify(data))
//循环所有项
// 循环所有项
const treeData = cloneData.filter((father) => {
const branchArr = cloneData.filter((child) => {
//返回每一项的子级数组
// 返回每一项的子级数组
return father[id] === child[parentId]
})
branchArr.length > 0 ? (father.children = branchArr) : ''
//返回第一层
// 返回第一层
return father[parentId] === rootId
})
return treeData !== '' ? treeData : data