【发布时间】:2021-10-04 15:56:43
【问题描述】:
我需要用深度嵌套的结构规范化 api 响应数据。 我正在使用这个https://github.com/paularmstrong/normalizr 来规范我的数据。
我有一个输入数据
const data = [{
id: 'component1,
name: 'component one,
properties:[{
name: 'text',
color: 'red'
}]
},
{
id: 'component2,
name: 'component two',
properties:[{
name: 'text',
color: 'yellow'
},{
name: 'button',
color: 'blue'
}]
}]
标准化后的预期输出
{
entities: {
component1: {
id: 'component1,
name: 'component one,
properties: {
entities: {
text: {
name: 'text',
color: 'red'
}
},
results: ['text']
}
},
component2: {
id: 'component2,
name: 'component two,
properties: {
entities: {
text: {
name: 'text',
color: 'yellow'
},
button: {
name: 'button',
color: 'blue'
}
},
results: ['text', 'button']
}
}
},
results: ['component1', 'component2']
}
请帮忙
【问题讨论】:
标签: javascript arrays json normalization normalizr