我有这么两段数据:
// 插入时间
const timeData = ['1:00','2:00','3:00','4:00','5:00':'6:00']
// 源数据
const sourceData={
parent1:{
child1:[1,2,3,4,5,6],
child2:[11,22,33,44,55,66],
child3:[111,222,333,444,555,666]
},
parent2:{
child1:[10,20,30,40,50,60],
child2:[110,220,330,440,550,660],
child3:[1110,2220,3330,4440,5550,6660]
},
parent3:{
child1:[101,202,303,404,505,606],
child2:[1101,2202,3303,4404,5505,6606],
child3:[11101,22202,33303,44404,55505,66606]
}
}
child 的 key 名和数组里面的数字随机,数组长度和时间数组一样 timeData.length === parent['child'].length
现在需要转换成如下格式的数据:
// 输出数据
const outputData = [
// parent1
{child1:{value:1}, child2:{value:11}, child3:{value:111}, time:{value:'1:00'}},
{child1:{value:2}, child2:{value:22}, child3:{value:222}, time:{value:'2:00'}},
{child1:{value:3}, child2:{value:33}, child3:{value:333}, time:{value:'3:00'}},
{child1:{value:4}, child2:{value:44}, child3:{value:444}, time:{value:'4:00'}},
{child1:{value:5}, child2:{value:55}, child3:{value:555}, time:{value:'5:00'}},
{child1:{value:6}, child2:{value:66}, child3:{value:666}, time:{value:'6:00'}},
// parent2
{child1:{value:10}, child2:{value:110}, child3:{value:1110}, time:{value:'1:00'}},
{child1:{value:20}, child2:{value:220}, child3:{value:2220}, time:{value:'2:00'}},
{child1:{value:30}, child2:{value:330}, child3:{value:3330}, time:{value:'3:00'}},
{child1:{value:40}, child2:{value:440}, child3:{value:4440}, time:{value:'4:00'}},
{child1:{value:50}, child2:{value:550}, child3:{value:5550}, time:{value:'5:00'}},
{child1:{value:60}, child2:{value:660}, child3:{value:6660}, time:{value:'6:00'}},
// parent2
{child1:{value:101}, child2:{value:1101}, child3:{value:11101}, time:{value:'1:00'},
{child1:{value:202}, child2:{value:2202}, child3:{value:22202}, time:{value:'2:00'},
{child1:{value:303}, child2:{value:3303}, child3:{value:33303}, time:{value:'3:00'},
{child1:{value:404}, child2:{value:4404}, child3:{value:44404}, time:{value:'4:00'},
{child1:{value:505}, child2:{value:5505}, child3:{value:55505}, time:{value:'5:00'},
{child1:{value:606}, child2:{value:6606}, child3:{value:66606}, time:{value:'6:00'},
]
想了好久卡这儿了,希望有大佬能提供实现方法
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.