From bdf49cd38a2d73559f64f2b8b48df106a8ba84b4 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Sun, 3 Dec 2023 19:14:33 +0800 Subject: [PATCH] fix: association field should support json field as title field (#3129) --- .../antd/association-field/InternalViewer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx index ff5a16465c..b6d19a6342 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx @@ -24,6 +24,9 @@ const toValue = (value, placeholder) => { } return value; }; +function isObject(value) { + return typeof value === 'object' && value !== null; +} export const ReadPrettyInternalViewer: React.FC = observer( (props: any) => { const fieldSchema = useFieldSchema(); @@ -45,11 +48,14 @@ export const ReadPrettyInternalViewer: React.FC = observer( const ellipsisWithTooltipRef = useRef(); const renderRecords = () => toArr(props.value).map((record, index, arr) => { + const value = record?.[fieldNames?.label || 'label']; const label = isTreeCollection ? transformNestedData(record) .map((o) => o?.[fieldNames?.label || 'label']) .join(' / ') - : record?.[fieldNames?.label || 'label']; + : isObject(value) + ? JSON.stringify(value) + : value; const val = toValue(compile(label), 'N/A'); const labelUiSchema = useLabelUiSchema( record?.__collection || collectionField?.target,