gpt4 book ai didi

javascript - Ra-data-simple-rest 不工作 |错误 : total is not a number and newRecords. forEach 不是函数

转载 作者:行者123 更新时间:2023-12-04 10:26:19 26 4
gpt4 key购买 nike

我正在尝试按照教程进行操作,现在我正处于必须实现的部分我自己的 REST-API。我的格式与教程中描述的所需格式相同。这是我的回复:The response from my API

所需的格式如下所示:

// {
// data: [
// { id: 126, title: "allo?", author_id: 12 },
// { id: 127, title: "bien le bonjour", author_id: 12 },
// { id: 124, title: "good day sunshine", author_id: 12 },
// { id: 123, title: "hello, world", author_id: 12 },
// { id: 125, title: "howdy partner", author_id: 12 },
// ],
// total: 27
// }

但出于某种原因,我总是得到这样的错误:(1) total 不是数字,但 postman 说是。并且 (2) newRecords.forEach 不是函数。

´´´

//App.js
import logo from './logo.svg';
import React from 'react';
import { Admin, Resource, ListGuesser } from 'react-admin';
import simpleRestProvider from 'ra-data-simple-rest';
import styles from './App.css';
import SimpleFlow from './diagramm';
import { RuleList, PostList} from './rules';

//http://jsonplaceholder.typicode.com'
const dataProvider = simpleRestProvider('http://localhost:3000/api');
const App = () =>
<Admin dataProvider={dataProvider} dashboard={SimpleFlow}>
<Resource name="rules" list={RuleList} />
</Admin>;

export default App;

´´´

´´´

//rules.js
import React from 'react';
import { List, Datagrid, TextField, EmailField, DateField, Pagination } from 'react-admin';

export const RuleList = (props) => (
<List {...props} perPage={25}>
<Datagrid rowClick="edit">
<TextField source="id" />
<TextField source="Bezeichnung" />
</Datagrid>
</List>

);

´´´

最佳答案

问题是由于您的数据样本格式引起的,在这种情况下,您的 API respose它是一个对象,但它需要是一个数组。像这样:

[
{ id: 126, title: "allo?", author_id: 12 },
{ id: 127, title: "bien le bonjour", author_id: 12 },
{ id: 124, title: "good day sunshine", author_id: 12 },
{ id: 123, title: "hello, world", author_id: 12 },
{ id: 125, title: "howdy partner", author_id: 12 }
]

关于javascript - Ra-data-simple-rest 不工作 |错误 : total is not a number and newRecords. forEach 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60622649/

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