@@ -271,7 +271,7 @@ export const useFieldFetchData = (
271
271
272
272
if ( children ) traverseFieldKey ( data , 'children' ) ;
273
273
if ( label ) traverseFieldKey ( data , 'label' ) ;
274
- if ( value ) traverseFieldKey ( data , 'value' ) ;
274
+ if ( value ) traverseFieldKey ( data , 'value' ) ;
275
275
return data ;
276
276
} , [ fieldProps ] ) ;
277
277
@@ -372,10 +372,23 @@ export const useFieldFetchData = (
372
372
373
373
return opt ;
374
374
} , [ options , keyWords , props . fieldProps ?. filterOption ] ) ;
375
+ const applyFieldNamesMapping = ( item : any ) => {
376
+ if ( ! fieldProps ?. fieldNames ) return item ;
375
377
378
+ const { label : labelKey = 'label' , value : valueKey = 'value' } = fieldProps . fieldNames ;
379
+
380
+ return {
381
+ ...item ,
382
+ label : item [ labelKey ] ,
383
+ value : item [ valueKey ] ,
384
+ } ;
385
+ } ;
386
+ const finalData = props . request
387
+ ? ( data as SelectOptionType ) ?. map ( ( item ) => applyFieldNamesMapping ( item ) )
388
+ : undefined ;
376
389
return [
377
390
isValidating ,
378
- props . request ? ( data as SelectOptionType ) : resOptions ,
391
+ finalData || resOptions ,
379
392
( fetchKeyWords ?: string ) => {
380
393
setKeyWords ( fetchKeyWords ) ;
381
394
} ,
@@ -417,8 +430,6 @@ const FieldSelect: ProFieldFC<
417
430
const inputRef = useRef ( ) ;
418
431
const intl = useIntl ( ) ;
419
432
const keyWordsRef = useRef < string > ( '' ) ;
420
- const { fieldNames } = fieldProps ;
421
-
422
433
useEffect ( ( ) => {
423
434
keyWordsRef . current = fieldProps ?. searchValue ;
424
435
} , [ fieldProps ?. searchValue ] ) ;
@@ -439,30 +450,32 @@ const FieldSelect: ProFieldFC<
439
450
const optionsValueEnum = useMemo ( ( ) => {
440
451
if ( mode !== 'read' ) return ;
441
452
442
- const {
443
- label : labelPropsName = 'label' ,
444
- value : valuePropsName = 'value' ,
445
- options : optionsPropsName = 'options' ,
446
- } = fieldNames || { } ;
447
-
448
- const valuesMap = new Map ( ) ;
449
-
450
453
const traverseOptions = ( _options : typeof options ) => {
454
+ const localMap = new Map ( ) ;
455
+
451
456
if ( ! _options ?. length ) {
452
- return valuesMap ;
457
+ return localMap ;
453
458
}
459
+
454
460
const length = _options . length ;
455
- let i = 0 ;
456
- while ( i < length ) {
457
- const cur = _options [ i ++ ] ;
458
- valuesMap . set ( cur [ valuePropsName ] , cur [ labelPropsName ] ) ;
459
- traverseOptions ( cur [ optionsPropsName ] ) ;
461
+ for ( let i = 0 ; i < length ; i ++ ) {
462
+ const cur = _options [ i ] ;
463
+
464
+ if ( cur . value !== undefined && cur . label !== undefined ) {
465
+ localMap . set ( cur . value , cur . label ) ;
466
+ }
467
+
468
+ if ( cur . options ?. length ) {
469
+ const childMap = traverseOptions ( cur . options ) ;
470
+ childMap . forEach ( ( v , k ) => localMap . set ( k , v ) ) ;
471
+ }
460
472
}
461
- return valuesMap ;
473
+
474
+ return localMap ;
462
475
} ;
463
476
464
477
return traverseOptions ( options ) ;
465
- } , [ fieldNames , mode , options ] ) ;
478
+ } , [ mode , options ] ) ;
466
479
467
480
if ( mode === 'read' ) {
468
481
const dom = (
0 commit comments