【发布时间】:2017-06-25 09:46:03
【问题描述】:
我不是在寻求帮助,我只是认为您的自定义 json-server 实现有问题。 我正在使用:“admin-on-rest”:“^1.1.0”
这是我的 App.js:
...
import restClient from './restClient';
const App = () => (
<Admin
title="Glasses"
dashboard={Dashboard}
menu={Menu}
restClient={restClient}
authClient={authClient}
>
<Resource name="products" list={ProductList} />
</Admin>
);
restClient.js 文件是https://github.com/marmelab/admin-on-rest/blob/master/src/rest/jsonServer.js 的副本,我只是将导入路径更改为:
import {
GET_LIST,
GET_ONE,
GET_MANY,
GET_MANY_REFERENCE,
CREATE,
UPDATE,
DELETE,
fetchUtils
} from 'admin-on-rest';
const { queryParameters, fetchJson } = fetchUtils;
...
其余的restClient.js一一如git "jsonServer.js"中的。
当我在菜单中单击“产品”时,我收到一条通知:“REST 响应必须包含数据键”,在控制台中:“警告:缺少键的翻译:“REST 响应必须包含数据键”
当然,现在看起来服务器没有在响应中返回“数据”对象,但问题是没有偶数请求!当我转到我的“网络”选项卡(在 Chrome 控制台过滤器到所有网络中)时,我没有看到对 API 的任何请求,那么怎么可能收到这种错误?
我在我的 restClient.js 文件 (jsonServer.js) 底部的这段代码的第一行添加了“console.log”:
return (type, resource, params) => {
console.log('test'); // THIS WHAT I ADDED
// json-server doesn't handle WHERE IN requests, so we fallback to calling GET_ONE n times instead
if (type === GET_MANY) {
return Promise.all(params.ids.map(id => httpClient(`${apiUrl}/${resource}/${id}`)))
.then(responses => ({ data: responses.map(response => response.json) }));
}
const { url, options } = convertRESTRequestToHTTP(type, resource, params);
return httpClient(url, options)
.then(response => convertHTTPResponseToREST(response, type, resource, params));
};
但“测试”没有打印到控制台。
有什么建议吗?我是不是做错了什么?
有帮助的视频:https://nimbus.everhelper.me/client/notes/share/982310/35f8rwpu6qohrftn8h1h restClient.js 文件:http://pasted.co/2024e00f
先谢谢你了。
狮子座。
【问题讨论】:
标签: admin-on-rest