fix: fixed the Select component not taking keys according to the corresponding value when passing fieldNames.

pull/8247/head
fanjunyang 2025-06-26 16:18:14 +08:00
parent 27acc9a80e
commit 6b54db676b
1 changed files with 6 additions and 4 deletions

View File

@ -2,11 +2,13 @@ import type { BaseOptionType, DefaultOptionType, RawValueType, FieldNames } from
import { warning } from '../../vc-util/warning';
import type { FlattenOptionData } from '../interface';
function getKey(data: BaseOptionType, index: number) {
function getKey(data: BaseOptionType, index: number, fieldNames?: FieldNames) {
const { key } = data;
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);
}
@ -54,7 +56,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
const value = data[fieldValue];
// Option
flattenList.push({
key: getKey(data, flattenList.length),
key: getKey(data, flattenList.length, fieldNames),
groupOption: isGroupOption,
data,
label,
@ -67,7 +69,7 @@ export function flattenOptions<OptionType extends BaseOptionType = DefaultOption
}
// Option Group
flattenList.push({
key: getKey(data, flattenList.length),
key: getKey(data, flattenList.length, fieldNames),
group: true,
data,
label: grpLabel,