我正在创建一个显示一些帖子的编辑器字段。
代码如下
export const EditorView = (props) => {
return (
<List {...props} title="Fresh Tales">
<Datagrid>
<TextField source="id" />
<TextField source="text" />
<ReferenceField label="Writer" source="writerId" reference="writers">
<TextField source="name" />
</ReferenceField>
</Datagrid>
</List>
)
}引用字段这里的文档
建议referenceField去重复API查询,而我在模拟API上为每个查询看到的查询是。我这里有两个问题。
1)每个查询都进行两次--一次使用选项,一次使用GET
2) ReferenceField中的每个编写器资源都是通过对Writers的一个查询来获取的。
OPTIONS /tales?_sort=ID&_order=ASC&_start=0&_end=10 204 0.168 ms - -
GET /tales?_sort=ID&_order=ASC&_start=0&_end=10 304 2.130 ms - -
OPTIONS /writers/312 204 0.148 ms - -
OPTIONS /writers/314 204 0.153 ms - -
OPTIONS /writers/316 204 0.190 ms - -
OPTIONS /writers/318 204 0.226 ms - -
OPTIONS /writers/320 204 0.116 ms - -
OPTIONS /writers/322 204 0.118 ms - -
OPTIONS /writers/324 204 0.142 ms - -
OPTIONS /writers/330 204 0.135 ms - -
OPTIONS /writers/340 204 0.122 ms - -
OPTIONS /writers/350 204 0.129 ms - -
GET /writers/312 304 1.769 ms - -
GET /writers/314 304 0.884 ms - -
GET /writers/316 304 4.023 ms - -
GET /writers/318 304 2.928 ms - -
GET /writers/320 304 0.759 ms - -
GET /writers/322 304 1.126 ms - -
GET /writers/324 304 1.040 ms - -
GET /writers/330 304 1.687 ms - -
GET /writers/340 304 0.653 ms - -
GET /writers/350 304 0.771 ms - -这似乎是相当沉重和浪费。将每个编写器加载到视图上是一个新的请求。我不知道是我错了还是医生错了。
发布于 2017-04-06 14:08:33
事实上,您看到一个OPTIONS和一个GET请求是CORS (交叉起源-资源共享-谷歌这个术语)的影响,如果你的API和管理员不在同一个领域的话,这是正常的。
至于将所有调用分组为一个(如果您的API支持它),在您的restClient中这样做是您的责任。
您可能使用的是自定义REST客户端或jsonServerRestClient,它不支持此选项。
例如,下面是如何实现simpleRestClient的
case GET_MANY: {
const query = {
filter: JSON.stringify({ id: params.ids }),
};
url = `${apiUrl}/${resource}?${queryParameters(query)}`;
break;
}https://stackoverflow.com/questions/43182151
复制相似问题