fix(cascader): menu not showing correct checked keys

This commit is contained in:
07akioni 2021-09-06 09:56:19 +08:00
parent 41f79ce285
commit 3380c7f521
3 changed files with 41 additions and 24 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG
## 2.17.1 (2021-09-06)
### Fixes
- Fix `n-cascader` menu not showing correct checked keys.
## 2.17.0 (2021-09-05)
### Breaking Changes

View File

@ -1,5 +1,11 @@
# CHANGELOG
## 2.17.1 (2021-09-06)
### Fixes
- 修复 `n-cascader` 菜单未展示正确的选中 key
## 2.17.0 (2021-09-05)
### Breaking Changes

View File

@ -203,8 +203,7 @@ export default defineComponent({
const { cascade, multiple } = props
if (multiple && Array.isArray(mergedValueRef.value)) {
return treeMateRef.value.getCheckedKeys(mergedValueRef.value, {
cascade,
checkStrategy: props.leafOnly ? 'child' : props.checkStrategy
cascade
})
} else {
return {
@ -329,29 +328,35 @@ export default defineComponent({
}
const selectedOptionsRef = computed(() => {
if (props.multiple) {
const { showPath, separator, labelField } = props
const { value } = checkedKeysRef
if (Array.isArray(value)) {
const { getNode } = treeMateRef.value
return value.map((key) => {
const node = getNode(key)
if (node === null) {
return {
label: String(key),
value: key
}
} else {
return {
label: showPath
? getPathLabel(node, separator, labelField)
: (node.rawNode as any)[labelField],
value: node.key
}
const {
showPath,
separator,
labelField,
cascade,
leafOnly,
checkStrategy
} = props
const { getCheckedKeys, getNode } = treeMateRef.value
const value = getCheckedKeys(checkedKeysRef.value, {
cascade,
checkStrategy: leafOnly ? 'child' : checkStrategy
}).checkedKeys
return value.map((key) => {
const node = getNode(key)
if (node === null) {
return {
label: String(key),
value: key
}
})
} else {
return []
}
} else {
return {
label: showPath
? getPathLabel(node, separator, labelField)
: (node.rawNode as any)[labelField],
value: node.key
}
}
})
} else return []
})
const selectedOptionRef = computed(() => {