获取记录中的字段值,以在<参考input>中使用。反应通用的过滤
我想使用记录字段的值来过滤一些自动完成选项,但是我不知道如何获取使用它的值。
<ReferenceInput source="text_resume_template_id" reference="text_templates"
filter={{ "client_id": my_client_id_value }}>
<AutocompleteInput optionText="name" />
</ReferenceInput>
在我编辑的记录中,我有“ client_id”字段,我想要的是从该字段获取值,并将其放入 my_client_id_value
中。
我知道,如果我想使用要编辑的记录的ID,我会使用:
export const ReportsEdit = () => {
const { id } = useParams()
return (...
我对Admin版本3.xx进行反应,我想我会使用类似的内容:(使用道具)
export const ClientsShow = props => {
return (
<Edit {...props}>
<ReferenceInput source="text_resume_template_id" reference="text_templates"
filter={{ "client_id": props.client_id }}>
<AutocompleteInput optionText="name" />
</ReferenceInput>
如何从中获取值client_id我的记录并将其用作过滤器?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 usercontextprovider ,但我无法使其起作用。
我使用的解决方案
是有效的,但是我想知道是否存在其他选项,而无需
Record -ContextProvider
(因为Edit> Edit
已经可以访问记录数据)。如果有人有其他答案,那会很好。
更新:
另一个选择:
使用FormData从字段中获取所选值(无需从记录中获取,可用于创建视图和更灵活的编辑)。
优点是,如果更改字段值,则将更新过滤器(仅在记录更改时,上一个选项才会更改)
I found my answer in the Show View documentation and I was not expecting to find it there because I'm working in the Edit.
I tried the
UserContextProvider
I found in other parts, but I couldn't make it work.The solution I used:
It worked, but I wonder if other option exists, without the need of the
RecordContextProvider
(because theEdit
already have access to the record data).If anyone have other answer, would be nice.
UPDATE:
Another option:
Using formData to get the selected values from a field (no need to get from record, useful to Create views and more flexible for Edit).
The advantage is that if you change the field value, the filter will be update (the previous option would only change if the record changed)