mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): should update selectedValues correctly
This commit is contained in:
parent
7dae50b0c9
commit
2a8bb86fbb
@ -21,6 +21,7 @@ import {
|
||||
BORDER_UNSET_TOP_BOTTOM,
|
||||
} from '../utils';
|
||||
import {
|
||||
isOptionExist,
|
||||
isValuesEqual,
|
||||
getColumnsType,
|
||||
findOptionByValue,
|
||||
@ -118,7 +119,7 @@ export default defineComponent({
|
||||
// reset values after cascading
|
||||
selectedValues.value.forEach((value, index) => {
|
||||
const options = currentColumns.value[index];
|
||||
if (!options.find((option) => option[fields.value.value] === value)) {
|
||||
if (!isOptionExist(options, value, fields.value)) {
|
||||
selectedValues.value[index] = options.length
|
||||
? options[0][fields.value.value]
|
||||
: undefined;
|
||||
@ -245,7 +246,10 @@ export default defineComponent({
|
||||
currentColumns,
|
||||
(columns) => {
|
||||
columns.forEach((options, index) => {
|
||||
if (selectedValues.value[index] === undefined && options.length) {
|
||||
if (
|
||||
options.length &&
|
||||
!isOptionExist(options, selectedValues.value[index], fields.value)
|
||||
) {
|
||||
selectedValues.value[index] =
|
||||
getFirstEnabledOption(options)[fields.value.value];
|
||||
}
|
||||
|
@ -38,6 +38,14 @@ export function findIndexOfEnabledOption(
|
||||
return 0;
|
||||
}
|
||||
|
||||
export const isOptionExist = (
|
||||
options: PickerOption[],
|
||||
value: number | string | undefined,
|
||||
fields: Required<PickerFieldNames>
|
||||
) =>
|
||||
value !== undefined &&
|
||||
!!options.find((option) => option[fields.value] === value);
|
||||
|
||||
export function findOptionByValue(
|
||||
options: PickerOption[],
|
||||
value: number | string,
|
||||
|
Loading…
x
Reference in New Issue
Block a user