@@ -39,7 +39,7 @@ const FormList: React.FC<TdFormListProps> = (props) => {
3939 } , [ fullPath , parentFullPath , initialDataFromForm , parentInitialData , props . initialData ] ) ;
4040
4141 const [ formListValue , setFormListValue ] = useState ( ( ) => {
42- const value = cloneDeep ( get ( form ?. store , fullPath ) || initialData || [ ] ) ;
42+ const value = get ( form ?. store , fullPath ) || initialData || [ ] ;
4343 if ( value . length && ! get ( form ?. store , fullPath ) ) {
4444 set ( form ?. store , fullPath , value ) ;
4545 }
@@ -65,22 +65,6 @@ const FormList: React.FC<TdFormListProps> = (props) => {
6565 . filter ( ( item ) => item !== undefined )
6666 . toString ( ) ; // 转化 name
6767
68- const buildDefaultFieldMap = ( ) => {
69- if ( formListMapRef . current . size <= 0 ) return { } ;
70- const defaultValues : Record < string , any > = { } ;
71- formListMapRef . current . forEach ( ( item , itemPath ) => {
72- const itemPathArray = convertNameToArray ( itemPath ) ;
73- const isChildField = itemPathArray . length === convertNameToArray ( fullPath ) . length + 2 ;
74- if ( ! isChildField ) return ;
75- const fieldName = itemPathArray [ itemPathArray . length - 1 ] ;
76- // add 没有传参时,构建一个包含所有子字段的对象用于占位,确保回调给用户的数据结构完整
77- // 兼容 add() 或者 add({}) 导致的空对象场景
78- // https://github.com/Tencent/tdesign-react/issues/2329
79- defaultValues [ fieldName ] = item . current . initialData ;
80- } ) ;
81- return defaultValues ;
82- } ;
83-
8468 const updateFormList = ( newFields : any , newFormListValue : any ) => {
8569 setFields ( newFields ) ;
8670 setFormListValue ( newFormListValue ) ;
@@ -98,12 +82,8 @@ const FormList: React.FC<TdFormListProps> = (props) => {
9882 name : index ,
9983 isListField : true ,
10084 } ) ;
101- const newFormListValue = cloneDeep ( formListValue ) ;
102- if ( defaultValue !== undefined ) {
103- newFormListValue . splice ( index , 0 , defaultValue ) ;
104- } else {
105- newFormListValue . splice ( index , 0 , buildDefaultFieldMap ( ) ) ;
106- }
85+ const newFormListValue = [ ...formListValue ] ;
86+ newFormListValue . splice ( index , 0 , cloneDeep ( defaultValue ) ) ;
10787 updateFormList ( newFields , newFormListValue ) ;
10888 } ,
10989 remove ( index : number | number [ ] ) {
0 commit comments