{"data": {
"char": [
[
[51, "逸", "毅", "char_2"],
[152, "参", "产", "char_2"],
],
[]
[
[29, "情", "清", "char_2"],
]
],
"miss": [
[
[291, "新", "心", "miss_1"],
[29, "新", "心", "miss_2"],
],
[]
],
"order": [
[]
]
}}
如何转换为
{
"big": {
"type": "char"
},
"small": [
{
"type": "char_2",
"correct": "毅",
"text": "逸",
"pos": "51",
"index": 0
},
{
"type": "char_2",
"correct": "参",
"text": "产",
"pos": "152",
"index": 0
},
{
"type": "",
"correct": "",
"text": "",
"pos": "",
"index": 1
},
{
"type": "char_2",
"correct": "清",
"text": "情",
"pos": "29",
"index": 2
},
]
},
{
"big": {
"type": "miss"
},
"small": [
{
"type": "miss_1",
"correct": "心",
"text": "新",
"pos": 291,
"index": 0
},
{
"type": "miss_1",
"correct": "心",
"text": "新",
"pos": 29,
"index": 0
},
{
"type": "",
"correct": "",
"text": "",
"pos": "",
"index": 1
},
]
}
]}
已解还有一点未完善关于[]部分
convert(data) {
return Object.entries(data)
.map(([type,list]) =>{
const big = {type}
const small = list.map((item,index)=>{
return item.map((it) =>{
const [pos, text, correct, type] = it;
return { pos, text, correct, type, index };
})
}).reduce((total, current) => {
return [...total, ...current]
}, [])
return {big,small}
})
},
const reslut = {
event_list: this.convert(res.data.data)
}
应该是你要的效果吧: