【发布时间】:2019-02-10 01:44:39
【问题描述】:
我正在尝试使用 simpleRestProvider。我的后端是弹簧靴。使用 starter web、data-rest 等。GET_LIST 端点的后端响应是:
{"content":[
{"id":1,"title":"Title One","content":"Content One","date":[2014,12,1,1,1],"published":true},
{"id":2,"title":"Title Two","content":"Content Two","date":[2015,2,10,1,1],"published":true}
]}
我无法克服来自 react-admin 的错误:
对“GET_LIST”的响应必须类似于 { data : [...] },但是 接收到的数据不是数组。 dataProvider 可能是错误的 'GET_LIST'
查看 react-admin 中的调试器,我看到我的响应已被包装在一个数据对象中,所以它看起来像这样:
数据:{内容:数组(2)}
并且在 ra-core.sideEffects 中 fetch.ts 的第 35 行失败
if (
fetchActionsWithArrayOfRecordsResponse.includes(type) &&
!Array.isArray(response.data)
) {
logger(
`The response to '${type}' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for '${type}'`
);
throw new Error('ra.notification.data_provider_error');
}
我知道发生了什么,response.data 不是一个数组,我嵌套的层次太深了。
我不能: A) 配置 react-admin 以查看我的响应,而不是将其包装在数据对象中 B) 从 spring 返回一个未封装在内容对象中的数组。
我错过了什么?
【问题讨论】: