【发布时间】:2019-12-09 08:38:45
【问题描述】:
我正在尝试使用ra-data-simple-rest data provider。
import React from 'react';
import { Admin, fetchUtils, Resource } from 'react-admin';
import simpleRestProvider from 'ra-data-simple-rest';
import { PostList } from './Posts';
const dataProvider = simpleRestProvider('http://localhost:8000');
const App = () => (
<Admin dataProvider={dataProvider}>
<Resource name="posts" list={PostList} />
</Admin>
);
export default App;
react-admin 监听http://localhost:3000/#/posts
Api 正在运行:http://localhost:8000/posts,它返回响应为。
$response = new JsonResponse($output);
$response->headers->set('Content-Range', 'posts 0-0/5');
$response->headers->set('Access-Control-Expose-Headers', 'Content-Range');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
将某些东西返回为
{
"data": [
{
"id": "1",
"title": "Hello world",
"body": "Hello world"
},
{
"id": "2",
"title": "Hello world",
"body": "Hello world"
}
],
"total": 2
}
我收到一个错误
对“GET_LIST”的响应必须类似于 { data : [...] },但接收到的数据不是数组。 'GET_LIST' 的 dataProvider 可能是错误的
如果data 键被删除为
[
{
"id": "1",
"title": "Hello world",
"body": "Hello world"
},
{
"id": "2",
"title": "Hello world",
"body": "Hello world"
}
]
正在得到结果。
【问题讨论】:
-
为支持 CORS 所做的更多更改。
-
由于某种原因,它显示 Failed to fetch 在哪里?
-
嗨,我已经更新了这个问题。
Failed to Fetch显示为红色,这是由于更多与 CORS 相关的问题。所以添加了适当的标题。当前问题是The response to 'GET_LIST' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'GET_LIST'
标签: react-admin