0

我不是在寻求帮助,我只是认为您的自定义 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

提前谢谢你。

狮子座。

4

1 回答 1

3

所以我的错误是我在没有 URL 的 Admin 组件中声明了 restClient 属性。

这是正确的方法:

const App = () => (
  <Admin
    title="Express Glasses"
    dashboard={Dashboard}
    menu={Menu}
    restClient={restClient('http://UrlToApi.com/api')}
    authClient={authClient}
  >
    <Resource name="products" list={ProductList} />
  </Admin>
);
于 2017-06-26T12:48:21.053 回答