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,
checkedKeys: { [key: string]: boolean }
): 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 keys = Object.keys(checkedKeys)
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++) {
const node = allNodes[i]
const nodeKey = node.data[key].toString()
@ -304,10 +312,8 @@ export default class TreeStore {
continue
}
let parent = node.parent
while (parent && parent.level > 0) {
cache[parent.data[key]] = true
parent = parent.parent
if (node.childNodes.length) {
cacheCheckedChild(node)
}
if (node.isLeaf || this.checkStrictly) {