预填充或将查询参数传递给 child 资源

prefill or pass query parameters to child resource

如何访问 child 资源创建表单中的查询参数?

例如,如果我想在 parent 资源编辑页面上有一个重定向到的按钮 /childresource/create?parentid=123 然后在 child 资源创建表单上我们有 <SelectInput source="parentid" /> 我想预选这个?

是否已经有可能了?使用自定义反应路由会更好,例如到 /parent/123/addchild 并拥有整个自定义创建组件或可能只是客户选择输入组件?

我已经为 child 创建了功能性的创建页面,但是以某种方式预填充值真的很好。

第二个问题的答案:

ProductSelect.defaultProps = {
  location: PropTypes.object.isRequired,
};

// This is the component exported and known by admin-on-rest, not ProductSelect
const EnhancedProductSelect = withRouter(ProductSelect);

// Hence, this is the one which needs a defaultProp for addField
EnhancedProductSelect.defaultProps = {
  addField: true
};

export default EnhancedProductSelect;

这对第一个问题有帮助吗?

https://codesandbox.io/s/pp0o4x40p0

相关代码部分为:

  • CreateCommentButton里面的组件src/posts.js
  • src/comments.js 中的 CommentCreate 组件(注意我们如何在 SimpleForm 上设置 defaultValue 属性)