mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-27 02:01:15 +08:00
fix(components): [tree] setCheckedNodes incorrectly checked node (#15377)
* fix(components): [tree] setCheckedNodes incorrectly checked node * fix: update * fix: update
This commit is contained in:
parent
758d375b7e
commit
345a374362
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user