Feat:copyRenderTree和copyNodeTree两个工具方法支持保留节点data和children以外的其他字段

This commit is contained in:
街角小林
2024-12-25 09:57:04 +08:00
parent d85210372d
commit 11c6fa3e45

View File

@@ -174,6 +174,12 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => {
tree.children[index] = copyRenderTree({}, item, removeActiveState)
})
}
// data、children外的其他字段
Object.keys(root).forEach((key) => {
if (!['data', 'children'].includes(key) && !/^_/.test(key)) {
tree[key] = root[key]
}
})
return tree
}
@@ -209,6 +215,12 @@ export const copyNodeTree = (
tree.children[index] = copyNodeTree({}, item, removeActiveState, removeId)
})
}
// data、children外的其他字段
Object.keys(root).forEach((key) => {
if (!['data', 'children'].includes(key) && !/^_/.test(key)) {
tree[key] = root[key]
}
})
return tree
}