gpt4 book ai didi

react-admin - 对 'GET_LIST' 的响应必须类似于 { data : [. ..] },但接收到的数据不是数组

转载 作者:行者123 更新时间:2023-12-04 11:47:34 24 4
gpt4 key购买 nike

我正在尝试使用 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
}

我收到一个错误

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'



如果 data键被删除为
[
{
"id": "1",
"title": "Hello world",
"body": "Hello world"
},
{
"id": "2",
"title": "Hello world",
"body": "Hello world"
}
]

正在得到结果。

最佳答案

最后我明白这是按 react 管理员的预期工作的。

问题出在 documentation我注意到

enter image description here

这让我很困惑。

深入了解 https://github.com/marmelab/react-admin/blob/1b6967f3367b13a6675de7047bd9385dc36a8db5/packages/ra-data-simple-rest/src/index.js#L118我知道数据是由提供者重建的。

关于react-admin - 对 'GET_LIST' 的响应必须类似于 { data : [. ..] },但接收到的数据不是数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57297317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com