【发布时间】:2018-01-02 12:03:08
【问题描述】:
我正在尝试使用 normalizer 来规范化一些 JSON。我的 JSON 看起来像
total: 8029,
items: [
{
id: 1,
name: 'Jacket1',
sku: '123',
upc: '1',
price: '99.99',
images: ['url1', 'url2'],
category: 'clothing',
thumbnail:
'https://cdn.zeplin.io/5969021e44c5978909d5278b/assets/1CE5FF07-E70F-4413-85BF-49C08AA559DE.png',
}, ...
从示例中,我认为这可能有效
const itemSchema = new schema.Entity('items')
const itemsSchema = new schema.Entity('result', {
items: [itemSchema],
})
const foo = normalize(fakeDatabase, itemsSchema)
但我最终得到了一个未定义的结果,并且该未定义的值包含一些时髦的东西。
我做错了什么?
【问题讨论】:
-
我不认为
itemsSchema是必要的。试试normalize(fakeDatabase, { items: [itemSchema] }) -
感谢您的回复。不幸的是,它没有用。我的 items 数组作为数字数组返回。我想我会用
lodash解决这个问题 -
@OrB 您的回答实际上是正确的。对于那个很抱歉。如果您添加该答案,我会将其标记为正确的。
标签: json redux react-redux normalizr