简体   繁体   English

react-admin获取标头X-Total-Count问题

[英]react-admin fetch header X-Total-Count issue

When use react-admin from frontend to call backend API, got this error from browser console: 当从前端使用react-admin调用后端API时,从浏览器控制台收到此错误:

Warning: Missing translation for key: "The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?"

If use ng-admin to call the backend API, it works well. 如果使用ng-admin调用后端API,则效果很好。

You need to add a header, named "X-Total-Count" in your responses To solve this. 您需要在响应中添加一个标题为“ X-Total-Count”的标题才能解决此问题。 The value of the of "X-Total-Count" should be equal to the total number of records. “ X-Total-Count”的值应等于记录总数。

Let's say you are fetching the list of comments, there are in total 125 comments in the database and you are fetching 25 records out of that. 假设您要获取注释列表,数据库中总共有125条注释,并且其中有25条记录。 Then the value of "X-Total-Count" should be 125. 然后,“ X-Total-Count”的值应为125。

It is being used for pagination. 它正在用于分页。

For example, here I attached a screenshot of Chrome Development tool. 例如,在这里,我附上了Chrome开发工具的屏幕截图。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM