如何从 Admin-on-rest 框架更改过滤器的密钥?

how to change key of filter from Admin-on-rest framework?

我在 Admin-on-rest 中使用 <Autocomplete> 组件。

<ReferenceInput label="Media" reference="Media" source="media_id" allowEmpty>
    <AutocompleteInput source="name" />
</ReferenceInput>

如果我在输入中输入内容,我的休息客户端会得到参数:

filter:{q: "1"}

我想替换名称上的 q,使其与我的来源相同。我该怎么做?

你应该在 custom restClient 中处理它。正如您在文档中看到的那样,它将接收查询类型(在本例中为 GET_LIST)、resource,以便您获得名称和带有 [=14= 的 params 对象].因此,您可以根据需要从该过滤器构建另一个对象,然后再将其发送到后端。

您可以使用 filterToQuery prop.

自定义 { q: [searchText] } 的默认行为
<ReferenceInput
     label="Media" 
     reference="Media" 
     source="media_id" 
     allowEmpty
     filterToQuery={searchText => ({ title: searchText })}>
    <AutocompleteInput source="name" />
</ReferenceInput>

您可以在 { title: searchText } 处将 title 更改为您想要发送到服务器的任何内容。

文档:https://marmelab.com/admin-on-rest/Inputs.html#referenceinput

在上方 link 中搜索 filterToQuery