fix: optional fields of the child collection cannot be displayed correctly in the parent collection (#2194)
This commit is contained in:
		
							parent
							
								
									f44c5f3b4a
								
							
						
					
					
						commit
						a3dc6d67e0
					
				@ -1,5 +1,6 @@
 | 
				
			|||||||
import { SchemaKey, useFieldSchema } from '@formily/react';
 | 
					import { SchemaKey, useFieldSchema } from '@formily/react';
 | 
				
			||||||
import React from 'react';
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import { useRecord } from '../record-provider';
 | 
				
			||||||
import { CollectionFieldContext } from './context';
 | 
					import { CollectionFieldContext } from './context';
 | 
				
			||||||
import { useCollection, useCollectionManager } from './hooks';
 | 
					import { useCollection, useCollectionManager } from './hooks';
 | 
				
			||||||
import { CollectionFieldOptions } from './types';
 | 
					import { CollectionFieldOptions } from './types';
 | 
				
			||||||
@ -12,8 +13,11 @@ export const CollectionFieldProvider: React.FC<{
 | 
				
			|||||||
  const { name, field, children, fallback = null } = props;
 | 
					  const { name, field, children, fallback = null } = props;
 | 
				
			||||||
  const fieldSchema = useFieldSchema();
 | 
					  const fieldSchema = useFieldSchema();
 | 
				
			||||||
  const { getField } = useCollection();
 | 
					  const { getField } = useCollection();
 | 
				
			||||||
 | 
					  const { __collection } = useRecord();
 | 
				
			||||||
  const { getCollectionJoinField } = useCollectionManager();
 | 
					  const { getCollectionJoinField } = useCollectionManager();
 | 
				
			||||||
  const value = field || getField(field?.name || name) || getCollectionJoinField(fieldSchema?.['x-collection-field']);
 | 
					  const value = __collection
 | 
				
			||||||
 | 
					    ? getCollectionJoinField(`${__collection}.${name}`)
 | 
				
			||||||
 | 
					    : field || getField(field?.name || name) || getCollectionJoinField(fieldSchema?.['x-collection-field']);
 | 
				
			||||||
  if (!value) {
 | 
					  if (!value) {
 | 
				
			||||||
    return fallback;
 | 
					    return fallback;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user