2017-05-08 5 views
1

RESTの管理者の新機能です。 /usersのための私の応答は、この上のようなものです:RESTの管理者リストの要素のパスを設定する方法

{ 
    "status": 200, 
    "response": { 
    "data": [ 
     { 
     "id": 298487355, 
     "login": "000000000053" 
     }, 
     ... 
    ] 
    } 
    "error": "text error" 
} 

私はresponseのパスを設定する方法:data[...]ユーザーのリストを取得するには? ありがとう

答えて

2

あなたはrestClientをカスタマイズできます。例えば、私はので、私はapp.jsでこれを持ってjsonServerで動作するように選択します。

import customRestClient from './customRestClient' 
const App =() => (
    <Admin restClient={customRestClient('http://path.to.my.api/')}> 

customRestClientは実際にthisファイルであり、私が輸入を調整し、私の元にそれを持って来ます。

このファイルは、あなたのデータがあなたのアプリからあなたのAPIに送られて行くポイントです。

のでconvertHTTPResponseToREST機能で、あなたは単にresourceをチェックすることができる、それはあなたが json.response.dataしてデータにアクセスし、switch

+0

おかげで、私はそれが動作 – Alexey

+0

はいを​​、しようとします。私はあなたに@ペラックありがとうございます。あなたは私の日を救う。あなたはこの機能のための管理者の休憩改善の提案についてどう思いますか、それはとても簡単で、価値がありません。 – Alexey

+0

あなたは私の日を保存する –

0

にそれを返すことができusersた場合のおかげで多くのことを@pelak。 私はあなたの答えにコードベースを書いています。

カスタムでrestClient応答データへのパスを指定します。

const convertHTTPResponseToREST = (response, type, resource, params) => { 
    const { headers, json } = response; 
    switch (type) { 
     case GET_LIST: 
     case GET_MANY_REFERENCE: 
      if (!headers.has('content-range')) { 
       throw new Error(
        'The Content-Range header is missing in the HTTP Response. The simple REST client 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 Content-Range in the Access-Control-Expose-Headers header?' 
       ); 
      } 
      // IF you just want use with **users** resource. 
      if(resource === 'users') { 
       return { 
        data: json.result, 
        total: parseInt(
         headers 
          .get('content-range') 
          .split('/') 
          .pop(), 
         10 
        ), 
       }; 
      } 
      return { 
       data: json.result, 
       total: parseInt(
        headers 
         .get('content-range') 
         .split('/') 
         .pop(), 
        10 
       ), 
      }; 
     case CREATE: 
      return { data: { ...params.data, id: json.id } }; 
     default: 
      return { data: json }; 
    } 
}; 

キーワード:子要素内のリストは、リストの巣

関連する問題