fix(components): [tree] setCheckedNodes incorrectly checked node (#15377)

* fix(components): [tree] setCheckedNodes incorrectly checked node

* fix: update

* fix: update
This commit is contained in:
btea 2024-01-16 16:26:30 +08:00 committed by GitHub
parent 758d375b7e
commit 345a374362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -289,10 +289,18 @@ export default class TreeStore {
leafOnly = false, leafOnly = false,
checkedKeys: { [key: string]: boolean } checkedKeys: { [key: string]: boolean }
): void { ): void {
const allNodes = this._getAllNodes().sort((a, b) => b.level - a.level) const allNodes = this._getAllNodes().sort((a, b) => a.level - b.level)
const cache = Object.create(null) const cache = Object.create(null)
const keys = Object.keys(checkedKeys) const keys = Object.keys(checkedKeys)
allNodes.forEach((node) => node.setChecked(false, false)) allNodes.forEach((node) => node.setChecked(false, false))
const cacheCheckedChild = (node) => {
node.childNodes.forEach((child) => {
cache[child.data[key]] = true
if (child.childNodes?.length) {
cacheCheckedChild(child)
}
})
}
for (let i = 0, j = allNodes.length; i < j; i++) { for (let i = 0, j = allNodes.length; i < j; i++) {
const node = allNodes[i] const node = allNodes[i]
const nodeKey = node.data[key].toString() const nodeKey = node.data[key].toString()
@ -304,10 +312,8 @@ export default class TreeStore {
continue continue
} }
let parent = node.parent if (node.childNodes.length) {
while (parent && parent.level > 0) { cacheCheckedChild(node)
cache[parent.data[key]] = true
parent = parent.parent
} }
if (node.isLeaf || this.checkStrictly) { if (node.isLeaf || this.checkStrictly) {