所有 normalizr 示例都集中在嵌套对象上,它们期望 API 结果如下所示:
{
id: 1,
title: 'Some Article',
author: {
id: 1,
name: 'Dan'
}
}
但我实际上发现,您必须自己加入集合的以下格式是我最常处理的格式,我可以使用 normalizr 为我处理这种情况吗?
Posts [{ _id: 1, name: 'post text 1', userId: 5, locationId: 8}]
Locations [{ _id: 8, name: 'New York'}]
Users [{ _id: 5, name: 'John Doe', country: 'US'}]
预期结果:
{
results: [1], // posts ids
entities: {
posts: {
1: { name: 'post text 1', userId: 5, locationId: 8 }
},
users: {
5: { name: 'John Doe', country: 'US' }
},
locations: {
8: { name: 'New York' },
}
}
}
据我所知,Docs/github 没有提到它