我正在使用normalizr處理從Api接收的數據。當我收到名單時,我會按預期得到正常化的實體。Normalizr未處理信封中的數據
但是當我發送更新一個實體的請求時,我收到的只是一個包裹在數據信封中的實體,沒有正確處理normalizr。
// Normalize setting
import { Schema, arrayOf } from 'normalizr'
export const player = new Schema('players')
export const arrayOfPlayers = arrayOf(player)
//This is what I use for normalize
response => normalize(response, {players: schema.player})
而且我喜歡在列表中,只有一名球員隨後接收數據:
{
code: 200,
message: '',
data: {
players: [{
id: 20
username: 'Gamer'
}]
}
}
我應該改變檢索玩家作爲標準化的實體?
更新:
API調用的例。
fetch(
url,
{ credentials: 'include' }
)
.then(checkStatus)
.then(response => response.json())
.then(response => normalize(response, {players: schema.player}))
.then(// dispatch redux action)
.catch(function (error) {
})
你能提供一個api調用的例子嗎? – mrtig
未經驗證的猜測:'normalize(response.data,...)'或'normalize(response,{data:{players:...}})'? – Bergi