用于规范化JSON的正确规范化程序语法
我正在尝试使用用于规范化JSON的正确规范化程序语法,json,redux,react-redux,normalizr,Json,Redux,React Redux,Normalizr,我正在尝试使用normalizer对一些JSON进行规范化。我的JSON看起来像 total: 8029, items: [ { id: 1, name: 'Jacket1', sku: '123', upc: '1', price: '99.99', images: ['url1', 'url2'], category: 'clothing', thumbnail:
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)
但我最终得到了一个未定义的结果,这个未定义的值中有一些古怪的东西
我做错了什么?我认为没有必要使用
itemschema
。尝试以下任一方法:
normalize(fakeDatabase, { items: new schema.Array(itemSchema) })
或
我认为没有必要使用
itemschema
。尝试以下任一方法:
normalize(fakeDatabase, { items: new schema.Array(itemSchema) })
或
我认为没有必要使用
itemschema
。请尝试normalize(fakeDatabase,{items:[itemSchema]})
谢谢您的回复。不幸的是,它没有起作用。my items数组作为数字数组返回。我想我会用lodash
@OrB解决这个问题,你的答案实际上是正确的。很抱歉。如果你加上这个答案,我会把它标记为正确答案。我认为没有必要使用itemschema
。请尝试normalize(fakeDatabase,{items:[itemSchema]})
谢谢您的回复。不幸的是,它没有起作用。my items数组作为数字数组返回。我想我会用lodash
@OrB解决这个问题,你的答案实际上是正确的。很抱歉。如果你加上那个答案,我会把它标为正确答案。