mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): error when options is empty
This commit is contained in:
parent
cca428aac6
commit
0186219586
@ -26,6 +26,7 @@ import {
|
||||
findOptionByValue,
|
||||
formatCascadeColumns,
|
||||
getFirstEnabledOption,
|
||||
assignDefaultFields,
|
||||
} from './utils';
|
||||
|
||||
// Composables
|
||||
@ -82,17 +83,7 @@ export default defineComponent({
|
||||
|
||||
linkChildren();
|
||||
|
||||
const fields = computed(
|
||||
(): Required<PickerFieldNames> =>
|
||||
extend(
|
||||
{
|
||||
text: 'text',
|
||||
value: 'value',
|
||||
children: 'children',
|
||||
},
|
||||
props.columnsFieldNames
|
||||
)
|
||||
);
|
||||
const fields = computed(() => assignDefaultFields(props.columnsFieldNames));
|
||||
const optionHeight = computed(() => unitToPx(props.optionHeight));
|
||||
const columnsType = computed(() =>
|
||||
getColumnsType(props.columns, fields.value)
|
||||
@ -128,7 +119,9 @@ export default defineComponent({
|
||||
selectedValues.value.forEach((value, index) => {
|
||||
const options = currentColumns.value[index];
|
||||
if (!options.find((option) => option[fields.value.value] === value)) {
|
||||
selectedValues.value[index] = options[0][fields.value.value];
|
||||
selectedValues.value[index] = options.length
|
||||
? options[0][fields.value.value]
|
||||
: undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { isDef, clamp } from '../utils';
|
||||
import { isDef, clamp, extend } from '../utils';
|
||||
import type { Ref } from 'vue';
|
||||
import type { PickerOption, PickerColumn, PickerFieldNames } from './types';
|
||||
|
||||
@ -95,3 +95,16 @@ export function isValuesEqual(
|
||||
valuesA.every((value, index) => value === valuesB[index])
|
||||
);
|
||||
}
|
||||
|
||||
export function assignDefaultFields(
|
||||
fields: PickerFieldNames | undefined
|
||||
): Required<PickerFieldNames> {
|
||||
return extend(
|
||||
{
|
||||
text: 'text',
|
||||
value: 'value',
|
||||
children: 'children',
|
||||
},
|
||||
fields
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user