[英]custom show form in react-admin
I try to create a customized form (Layout) with flexbox for a show view in react-admin and I don't know where to start.我尝试为 react-admin 中的显示视图创建一个带有 flexbox 的自定义表单(布局),但我不知道从哪里开始。
For the Create and Edit view we can use 'FormWithRedirect' as explained in the react-admin docu to create a custom view for example with flexbox: https://marmelab.com/react-admin/CreateEdit.html对于创建和编辑视图,我们可以使用 react-admin 文档中解释的“FormWithRedirect”来创建自定义视图,例如使用 flexbox: https ://marmelab.com/react-admin/CreateEdit.html
const VisitorForm = props => (
<FormWithRedirect
{...props}
render={formProps => (
// here starts the custom form layout
<form>
<Box p="1em">
.....
<TextInput source="first_name" resource="customers" fullWidth />
When trying to render the show view with flexbox elements, then the react-admin components are not rendered.当尝试使用 flexbox 元素渲染显示视图时,不会渲染 react-admin 组件。 What is the equivalent approach for a show-view?
显示视图的等效方法是什么? How can I use flexbox in a show-view?
如何在显示视图中使用 flexbox?
export const PostShow = (props) => (
<Show {...props}>
<SimpleShowLayout>
<Box><TextField source="title" /></Box> // TextField is not rendered.
You should create an alternative show layout component.您应该创建一个替代的显示布局组件。 It'll receive a
record
prop, which contains the data fetched from the dataProvider:它将接收一个
record
道具,其中包含从 dataProvider 获取的数据:
const MyShowLayout = ({ record }) => (
<Box>
// use record directly
<Typography>{record.title}</Typography>
// or use react-admin components by passing record
<TextField source="title" record={record} />
</Box>
);
Then, use your custom layout in the PostShow, as follows:然后,在 PostShow 中使用您的自定义布局,如下所示:
const PostShow = props => (
<Show {...props}>
<MyShowLayout />
</Show>
);
When rendering, the <Show>
component clones its child and passes the fetched record
.渲染时,
<Show>
组件会克隆其子组件并传递获取的record
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.