如何获取 API 提供的 <Edit> 内的记录值?
How to get the API provided record values within <Edit>?
我在编辑视图中有一个 ArrayInput。
<Edit undoable={false} {...props} title={<AdTitle />} >
<TabbedForm>
<FormTab label="summary">
<ArrayInput source="siteads" addLabel={false}>
<SimpleFormIterator disableRemove disableAdd>
{ record.status === 0 && <TextInput label="Hivatkozas" source="href" props={{ disabled: true }}/> }
</SimpleFormIterator>
</ArrayInput>
</FormTab>
</TabbedForm>
</Edit>
如何在“编辑”视图中获取记录的 fields/values?
这里也可以使用 FormDataConsumer,文档中的示例:
"You're using a FormDataConsumer inside an ArrayInput and you did not called the getSource function supplied by the FormDataConsumer component. This is required for your inputs to get the proper source"
<ArrayInput source="users">
<SimpleFormIterator>
<TextInput source="name" />
<FormDataConsumer>
{({
formData, // The whole form data
scopedFormData, // The data for this item of the ArrayInput
getSource, // A function to get the valid source inside an ArrayInput
...rest,
}) =>
scopedFormData.name ? (
<SelectInput
source={getSource('role')} // Will translate to "users[0].role"
choices={['admin', 'user']}
{...rest}
/>
) : null
}
</FormDataConsumer>
</SimpleFormIterator>
</ArrayInput>
我在编辑视图中有一个 ArrayInput。
<Edit undoable={false} {...props} title={<AdTitle />} >
<TabbedForm>
<FormTab label="summary">
<ArrayInput source="siteads" addLabel={false}>
<SimpleFormIterator disableRemove disableAdd>
{ record.status === 0 && <TextInput label="Hivatkozas" source="href" props={{ disabled: true }}/> }
</SimpleFormIterator>
</ArrayInput>
</FormTab>
</TabbedForm>
</Edit>
如何在“编辑”视图中获取记录的 fields/values?
这里也可以使用 FormDataConsumer,文档中的示例:
"You're using a FormDataConsumer inside an ArrayInput and you did not called the getSource function supplied by the FormDataConsumer component. This is required for your inputs to get the proper source"
<ArrayInput source="users">
<SimpleFormIterator>
<TextInput source="name" />
<FormDataConsumer>
{({
formData, // The whole form data
scopedFormData, // The data for this item of the ArrayInput
getSource, // A function to get the valid source inside an ArrayInput
...rest,
}) =>
scopedFormData.name ? (
<SelectInput
source={getSource('role')} // Will translate to "users[0].role"
choices={['admin', 'user']}
{...rest}
/>
) : null
}
</FormDataConsumer>
</SimpleFormIterator>
</ArrayInput>