我使用ReferenceManyField来显示订单中的项目,即典型的主/详细数据库模式。我能够编辑现有的详细记录,但无法找到添加新详细记录的方法。我尝试了以下内容,但没有像{id}那样收到。我注意到admin-on-rest-demo允许编辑详细记录(产品评论),但不允许添加评论。有这样的模式或解决方法吗?
<SimpleForm>
<ReferenceManyField label="ITEMS" reference="orderitems" target="orderId">
<Datagrid>
// fields removed for clarity...
<CreateButton/> <===== does not pass {id} of form record
<EditButton/> <===== passes {id} of form record
</Datagrid>
</ReferenceManyField>
</SimpleForm>
答案 0 :(得分:0)
我回答了这个问题here:
示例:https://codesandbox.io/s/pp0o4x40p0
相关的代码部分是:
CreateCommentButton
src/posts.js
组件
CommentCreate
内的src/comments.js
组件(请注意我们如何在defaultValue
上设置SimpleForm
道具)