对' getList的响应'必须像{data:[...]}一样,但是接收到的数据不是数组。 React Admin错误

发布于 2025-02-06 14:18:39 字数 2666 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

峩卟喜欢 2025-02-13 14:18:40

该解决方案期望以这种格式挖掘的响应

{
    "count": 10,
    "next": "http://127.0.0.1:8000/api/products/?page=2",
    "previous": null,
    "results": [
        {
            "id": 10,
            "product_title": "Crompton pedastal fan",
            "product_description": "Nice Crompton pedastal fan",
        },
        {
            "id": 10,
            "product_title": "Crompton pedastal fan",
            "product_description": "Nice Crompton pedastal fan",
        }
    ]
}

可以深入打开,它可以与基于类的视图(如仿制药视图)无缝地运行,我在django中使用了基于函数的视图。现在,我更改为基于班级的视图,一切正常。

class ProductList (generics.ListCreateAPIView):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer

The solution , it expects the response in this format

{
    "count": 10,
    "next": "http://127.0.0.1:8000/api/products/?page=2",
    "previous": null,
    "results": [
        {
            "id": 10,
            "product_title": "Crompton pedastal fan",
            "product_description": "Nice Crompton pedastal fan",
        },
        {
            "id": 10,
            "product_title": "Crompton pedastal fan",
            "product_description": "Nice Crompton pedastal fan",
        }
    ]
}

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.

class ProductList (generics.ListCreateAPIView):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文