对' getList的响应'必须像{data:[...]}一样,但是接收到的数据不是数组。 React Admin错误
The response to 'getList' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getList'
响应
{
"data": [
{
"id": 6,
"product_title": "Foam chair",
"product_description": "Fantastic Foam chair",
},
{
"id": 5,
"product_title": "Shinez cleaning liquid",
"product_description": "Shinez cleaning liquid shoes is good for electronics",
},
{
"id": 4,
"product_title": "Shinez cleaning liquid buy 1 get 1 free",
"product_description": "Shinez cleaning liquid shoes is a good for electronics and computers",
},
{
"id": 3,
"product_title": "Raj kiran Motor cycle",
"product_description": "Raj kiran Motor cycle old one",
},
{
"id": 2,
"product_title": "Ka ka cycle broken cycle",
"product_description": "Ka ka cycle broken into multiple pieces",
},
{
"id": 1,
"product_title": "ka ka police cap",
"product_description": "This is police cap used by ka team",
}
]
}
,但我仍然得到
The response to 'getList' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getList'
实际代码
<BrowserRouter>
<Admin catchAll={NotFound}
dataProvider={dataProvider}
authProvider={authProvider}
loginPage={myLoginPage} >
</Admin>
</BrowserRouter>
这里是我正在使用Django Rest框架作为后端的
,并使用“ Ra-Data-Data-Data-django-Rest-Framework”需要帮助。多谢。
看看以下问题 react-admin“获取列表” dataprovider
对'get_list'的响应必须像{data:[... ]},但是收到的数据不是数组
const fetchJson = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
// Not working even if add content-range
// Content-Range: posts 0-24/319,
//adding console.log , returns undefined here
console.log( fetchUtils.fetchJson );
return fetchUtils.fetchJson(url, options);
}
const dataProvider = drfProvider('http://127.0.0.1:8000/api', fetchJson);
imp。信息:我应要求收到回复。
添加控制台。log,返回未定义。
The response to 'getList' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getList'
Response
{
"data": [
{
"id": 6,
"product_title": "Foam chair",
"product_description": "Fantastic Foam chair",
},
{
"id": 5,
"product_title": "Shinez cleaning liquid",
"product_description": "Shinez cleaning liquid shoes is good for electronics",
},
{
"id": 4,
"product_title": "Shinez cleaning liquid buy 1 get 1 free",
"product_description": "Shinez cleaning liquid shoes is a good for electronics and computers",
},
{
"id": 3,
"product_title": "Raj kiran Motor cycle",
"product_description": "Raj kiran Motor cycle old one",
},
{
"id": 2,
"product_title": "Ka ka cycle broken cycle",
"product_description": "Ka ka cycle broken into multiple pieces",
},
{
"id": 1,
"product_title": "ka ka police cap",
"product_description": "This is police cap used by ka team",
}
]
}
But still I get the
The response to 'getList' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getList'
here is the actual code
<BrowserRouter>
<Admin catchAll={NotFound}
dataProvider={dataProvider}
authProvider={authProvider}
loginPage={myLoginPage} >
</Admin>
</BrowserRouter>
I am using django rest framework as backend and using 'ra-data-django-rest-framework'
Need help on this. Thanks a lot.
Had a look at the following questions
React-Admin "Get List" DataProvider
The response to 'GET_LIST' must be like { data : [...] }, but the received data is not an array
const fetchJson = (url, options = {}) => {
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' });
}
// Not working even if add content-range
// Content-Range: posts 0-24/319,
//adding console.log , returns undefined here
console.log( fetchUtils.fetchJson );
return fetchUtils.fetchJson(url, options);
}
const dataProvider = drfProvider('http://127.0.0.1:8000/api', fetchJson);
Imp. info: I am receiving the response on request.
adding console.log , returns undefined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该解决方案期望以这种格式挖掘的响应
可以深入打开,它可以与基于类的视图(如仿制药视图)无缝地运行,我在django中使用了基于函数的视图。现在,我更改为基于班级的视图,一切正常。
The solution , it expects the response in this format
Digging deep opens up that, it works seamlessly with class-based views like generics view, I was using function-based view in Django. Now I changed to class based view, everything is working cool.