Javascript 如何格式化react admin中ReferenceInput字段中的选项文本?

Javascript 如何格式化react admin中ReferenceInput字段中的选项文本?,javascript,reactjs,react-admin,Javascript,Reactjs,React Admin,ReferenceInput字段与SelectInput相结合,通过提供列名称,可以从引用资源的列中填充选项文本,如下所示: <ReferenceInput label="Location name" source="id" reference="Location"> <SelectInput optionText={"building"} /> </ReferenceInput> 我想合并多个列中的选项文本,但我不知道如何访问当前记录。 我想在这段代

ReferenceInput字段与SelectInput相结合,通过提供列名称,可以从引用资源的列中填充选项文本,如下所示:

<ReferenceInput label="Location name" source="id" reference="Location">
 <SelectInput optionText={"building"} />
</ReferenceInput>

我想合并多个列中的选项文本,但我不知道如何访问当前记录。 我想在这段代码中实现类似的功能(当然,这不起作用,只是为了说明我的意思):


optionText
还接受一个函数,因此您可以随意塑造选项文本:

const choices = [
   { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
   { id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
<SelectInput source="author_id" choices={choices} optionText={optionRenderer} />

太好了,谢谢!所以它实际上叫做记录,我不远:)
const choices = [
   { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
   { id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
<SelectInput source="author_id" choices={choices} optionText={optionRenderer} />
const choices = [
   { id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
   { id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const FullNameField = ({ record }) => <span>{record.first_name} {record.last_name}</span>;
<SelectInput source="gender" choices={choices} optionText={<FullNameField />}/>