您实际上可以操纵<List>
之外的任何字段,然后让<Datagrid>
呈现该字段,只要它是迭代的即可。
const CustomTitleField = ({ record }) => { // "record" is a prop received from the Datagrid let str = record.title; return record ? ( {/* If length is greater than 20 characters, slice and add ellipsis.*/} <span>{str.length > 20 ? str.slice(0, 20) + "..." : str}</span> ) : null; }; // Then, within your list, do this... export const CommentList => ( <List {...props}> <Datagrid> <CustomTitleField /> // this should render with your truncate logic // ... </Datagrid> </List> );
尝试一下后,让我知道如何运行!