react-admin - 编辑表单中的显示字段
问题描述
目前,如果我尝试将字段放入编辑表单中,则该字段根本不会显示。控制台或终端中没有关于它为什么不会的错误。
例子:
<Edit undoable={false} {...props}>
<SimpleForm>
<FormRow>
<TextField source="id"/>
<TextField source="name"/>
</FormRow>
</SimpleForm>
</Edit>
不会在页面加载时显示其中任何一个,它只会是空白的。
有没有办法使用编辑表单中的字段?
解决方案
You need to pass in the record prop (and basePath if its a reference).
The Edit component does not get the record prop so create a form component and it will get passed the record as a prop
eg.
const ProjectEdit: FC<EditComponentProps> = props => {
const classes = useStyles();
return (
<RA.Edit {...props} title={<ProjectTitle />}>
<RA.SimpleForm>
<ProjectForm />
</RA.SimpleForm>
</RA.Edit>
);
};
export const ProjectForm = (props: any) => {
return (
<Box flex={1} mr={{ md: 0, lg: '1em' }}>
<RA.TextInput source="name" fullWidth={true} />
<Typography variant="h6" gutterBottom>
Tasks
</Typography>
<RA.TextField
source="name"
fullWidth={true}
record={props.record}
/>
<RA.ReferenceManyField
label="Tasks"
reference="Task"
target="projectId"
fullWidth={true}
record={props.record}
basePath="/Task"
>
<RA.SingleFieldList fullWidth={true}>
<RA.ChipField source="name" fullWidth={true} />
</RA.SingleFieldList>
</RA.ReferenceManyField>
</Box>
);
};
推荐阅读
- tensorflow - 深度学习的照片大小是否应该相同?
- python - 尝试一次从多个网站提取数据但不能
- r - 如何修复“x[(i - z):(i + y)] 中的错误:只有 0 可能与负下标混合?
- r - 为什么我的 ccdf 图从 0.4 而不是 1 开始?
- s4sdk - 无法获取元数据:无法执行 OData 元数据请求。将 s4sdk 部署到 Cloud Foundry 后出错
- java - 如何显示来自 ArrayList 的图像
(SQLite) - c++ - 具有 0..n 参数的跨平台可变参数宏
- html - 在“p”标签内带有“href”属性的“a”标签
- c# - C# 在异步 void 完成后打开一个 void
- amazon-web-services - 参数 cidrBlock 的值 (PrivateSubnet2CIDR) 无效。这不是有效的 CIDR 块。这是我得到的错误