fix: fixed the Select component not taking keys according to the corresponding value when passing fieldNames.
parent
27acc9a80e
commit
6b54db676b
|
@ -2,11 +2,13 @@ import type { BaseOptionType, DefaultOptionType, RawValueType, FieldNames } from
|
||||||
import { warning } from '../../vc-util/warning';
|
import { warning } from '../../vc-util/warning';
|
||||||
import type { FlattenOptionData } from '../interface';
|
import type { FlattenOptionData } from '../interface';
|
||||||
|
|
||||||
function getKey(data: BaseOptionType, index: number) {
|
function getKey(data: BaseOptionType, index: number, fieldNames?: FieldNames) {
|
||||||
const { key } = data;
|
const { key } = data;
|
||||||
let value: RawValueType;
|
let value: RawValueType;
|
||||||
|
|
||||||
if ('value' in data) {
|
if (fieldNames && fieldNames.value && data[fieldNames.value] !== undefined) {
|
||||||
|
({ [fieldNames.value]: value } = data);
|
||||||
|
} else if ('value' in data) {
|
||||||
({ value } = data);
|
({ value } = data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +56,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
|
||||||
const value = data[fieldValue];
|
const value = data[fieldValue];
|
||||||
// Option
|
// Option
|
||||||
flattenList.push({
|
flattenList.push({
|
||||||
key: getKey(data, flattenList.length),
|
key: getKey(data, flattenList.length, fieldNames),
|
||||||
groupOption: isGroupOption,
|
groupOption: isGroupOption,
|
||||||
data,
|
data,
|
||||||
label,
|
label,
|
||||||
|
@ -67,7 +69,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
|
||||||
}
|
}
|
||||||
// Option Group
|
// Option Group
|
||||||
flattenList.push({
|
flattenList.push({
|
||||||
key: getKey(data, flattenList.length),
|
key: getKey(data, flattenList.length, fieldNames),
|
||||||
group: true,
|
group: true,
|
||||||
data,
|
data,
|
||||||
label: grpLabel,
|
label: grpLabel,
|
||||||
|
|
Loading…
Reference in New Issue