mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Picker): allow option text to be number type (#8951)
This commit is contained in:
parent
17c5c5d8a7
commit
e366b336e3
@ -94,7 +94,11 @@ export default defineComponent({
|
|||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const formattedColumns = ref<PickerObjectColumn[]>([]);
|
const formattedColumns = ref<PickerObjectColumn[]>([]);
|
||||||
|
|
||||||
const { text: textKey, values: valuesKey, children: childrenKey } = extend(
|
const {
|
||||||
|
text: textKey,
|
||||||
|
values: valuesKey,
|
||||||
|
children: childrenKey,
|
||||||
|
} = extend(
|
||||||
{
|
{
|
||||||
// compatible with valueKey prop
|
// compatible with valueKey prop
|
||||||
text: props.valueKey,
|
text: props.valueKey,
|
||||||
@ -104,9 +108,8 @@ export default defineComponent({
|
|||||||
props.columnsFieldNames
|
props.columnsFieldNames
|
||||||
);
|
);
|
||||||
|
|
||||||
const { children, linkChildren } = useChildren<ComponentInstance>(
|
const { children, linkChildren } =
|
||||||
PICKER_KEY
|
useChildren<ComponentInstance>(PICKER_KEY);
|
||||||
);
|
|
||||||
|
|
||||||
linkChildren();
|
linkChildren();
|
||||||
|
|
||||||
@ -114,7 +117,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
const dataType = computed(() => {
|
const dataType = computed(() => {
|
||||||
const firstColumn = props.columns[0];
|
const firstColumn = props.columns[0];
|
||||||
if (firstColumn && typeof firstColumn !== 'string') {
|
if (typeof firstColumn === 'object') {
|
||||||
if (childrenKey in firstColumn) {
|
if (childrenKey in firstColumn) {
|
||||||
return 'cascade';
|
return 'cascade';
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,13 @@ function getElementTranslateY(element: Element) {
|
|||||||
export const PICKER_KEY = Symbol(name);
|
export const PICKER_KEY = Symbol(name);
|
||||||
|
|
||||||
export type PickerObjectOption = {
|
export type PickerObjectOption = {
|
||||||
text?: string;
|
text?: string | number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
// for custom filed names
|
// for custom filed names
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PickerOption = string | PickerObjectOption;
|
export type PickerOption = string | number | PickerObjectOption;
|
||||||
|
|
||||||
export type PickerObjectColumn = {
|
export type PickerObjectColumn = {
|
||||||
values?: PickerOption[];
|
values?: PickerOption[];
|
||||||
|
@ -360,7 +360,7 @@ Picker events will pass different parameters according to the columns are single
|
|||||||
|
|
||||||
| Key | Description | Type |
|
| Key | Description | Type |
|
||||||
| ------------ | ------------------------- | --------------------------- |
|
| ------------ | ------------------------- | --------------------------- |
|
||||||
| values | Value of column | _string[]_ |
|
| values | Value of column | _Array<string \| number>_ |
|
||||||
| defaultIndex | Default value index | _number_ |
|
| defaultIndex | Default value index | _number_ |
|
||||||
| className | ClassName for this column | _string \| Array \| object_ |
|
| className | ClassName for this column | _string \| Array \| object_ |
|
||||||
| children | Cascade children | _Column_ |
|
| children | Cascade children | _Column_ |
|
||||||
|
@ -359,7 +359,7 @@ export default {
|
|||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
当选择器有多列时,事件回调参数会返回数组
|
当选择器有多列时,事件回调参数会返回数组。
|
||||||
|
|
||||||
| 事件名 | 说明 | 回调参数 |
|
| 事件名 | 说明 | 回调参数 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
@ -385,7 +385,7 @@ export default {
|
|||||||
|
|
||||||
| 键名 | 说明 | 类型 |
|
| 键名 | 说明 | 类型 |
|
||||||
| ------------ | -------------------------- | --------------------------- |
|
| ------------ | -------------------------- | --------------------------- |
|
||||||
| values | 列中对应的备选值 | _string[]_ |
|
| values | 列中对应的备选值 | _Array<string \| number>_ |
|
||||||
| defaultIndex | 初始选中项的索引,默认为 0 | _number_ |
|
| defaultIndex | 初始选中项的索引,默认为 0 | _number_ |
|
||||||
| className | 为对应列添加额外的类名 | _string \| Array \| object_ |
|
| className | 为对应列添加额外的类名 | _string \| Array \| object_ |
|
||||||
| children | 级联选项 | _Column_ |
|
| children | 级联选项 | _Column_ |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user