我想规范化从 API 收到的响应。典型的响应可能如下所示:
// Get all projects
{data:[
{
id: 1
...
team:{
data: {
id:15
...
}
}
},
{
id:2,
....
},
{
id:3,
...
}
]}
如何编写模式以删除“数据”容器?目前,我的架构如下所示:
export const project = new schema.Entity('projects', {
team: team, // team omitted
},
{
processStrategy: (value, parent, key) => parent.data
}
)
export const arrayOfProjects = new schema.Array(project)
我像这样使用它:
const normalizedProjects = normalize(jsonResponse, arrayOfProjects)
normalizedProjects然后看起来像这样:
{
entities:{
projects:{
undefined:{
0:{
team:{
data:{
id:15,
...
}
}
},
1:{...},
2:{...}.
...
50:{...},
}
}
},
result:[] // length is 0
}
我也不确定为什么项目列表包含在“未定义”中?