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,
|
BORDER_UNSET_TOP_BOTTOM,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import {
|
import {
|
||||||
|
isOptionExist,
|
||||||
isValuesEqual,
|
isValuesEqual,
|
||||||
getColumnsType,
|
getColumnsType,
|
||||||
findOptionByValue,
|
findOptionByValue,
|
||||||
@ -118,7 +119,7 @@ export default defineComponent({
|
|||||||
// reset values after cascading
|
// reset values after cascading
|
||||||
selectedValues.value.forEach((value, index) => {
|
selectedValues.value.forEach((value, index) => {
|
||||||
const options = currentColumns.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
|
selectedValues.value[index] = options.length
|
||||||
? options[0][fields.value.value]
|
? options[0][fields.value.value]
|
||||||
: undefined;
|
: undefined;
|
||||||
@ -245,7 +246,10 @@ export default defineComponent({
|
|||||||
currentColumns,
|
currentColumns,
|
||||||
(columns) => {
|
(columns) => {
|
||||||
columns.forEach((options, index) => {
|
columns.forEach((options, index) => {
|
||||||
if (selectedValues.value[index] === undefined && options.length) {
|
if (
|
||||||
|
options.length &&
|
||||||
|
!isOptionExist(options, selectedValues.value[index], fields.value)
|
||||||
|
) {
|
||||||
selectedValues.value[index] =
|
selectedValues.value[index] =
|
||||||
getFirstEnabledOption(options)[fields.value.value];
|
getFirstEnabledOption(options)[fields.value.value];
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,14 @@ export function findIndexOfEnabledOption(
|
|||||||
return 0;
|
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(
|
export function findOptionByValue(
|
||||||
options: PickerOption[],
|
options: PickerOption[],
|
||||||
value: number | string,
|
value: number | string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user