用于规范化 JSON 的更正规范化器语法
Correct normalizer syntax for normalizing JSON
我正在尝试使用 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: new schema.Array(itemSchema) })
或
normalize(fakeDatabase, { items: [itemSchema] })
我正在尝试使用 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: new schema.Array(itemSchema) })
或
normalize(fakeDatabase, { items: [itemSchema] })