这是我从SQL数据库中获取的javascript对象数据:
0: {ww: "2021-27", area: "F15 WET PROCESS", dissection_name: "WAIT_OTHERS", waiting_time: 5.3670104041}
1: {ww: "2021-26", area: "F15 METROLOGY", dissection_name: "DELIVERY_TIME", waiting_time: 0}
2: {ww: "2021-26", area: "F15 WET PROCESS", dissection_name: "WAIT_FOR_START_RUNNING", waiting_time: 0.1858817617}
3: {ww: "2021-25", area: "F15 CMP", dissection_name: "BATCH_WAIT_TIME", waiting_time: 0}
4: {ww: "2021-25", area: "F15 GENERAL", dissection_name: "WAIT_OTHERS", waiting_time: 0.0326702424}
5: {ww: "2021-27", area: "F15 DRY ETCH", dissection_name: "DELIVERY_TIME", waiting_time: 0}
6: {ww: "2021-27", area: "F15 DIFFUSION", dissection_name: "BATCH_WAIT_TIME", waiting_time: 1.544808954}
7: {ww: "2021-24", area: "F15 METROLOGY", dissection_name: "WAIT_FOR_START_RUNNING", waiting_time: 0.0270019481}
8: {ww: "2021-24", area: "F15 PHOTO", dissection_name: "BATCH_WAIT_TIME", waiting_time: 0.0001341795}
9: {ww: "2021-24", area: "F15 DRY ETCH", dissection_name: "DELIVERY_TIME", waiting_time: 0}
我想对它进行一些操作,这样' waiting_time ';列名将被更改为每个数据块的'w '值,以转换对象结构,如下所示:
0: {area: "F15 WET PROCESS", dissection_name: "WAIT_OTHERS", 2021-27: 5.3670104041}
1: { area: "F15 METROLOGY", dissection_name: "DELIVERY_TIME", 2021-27: 0}
2: { area: "F15 WET PROCESS", dissection_name: "WAIT_FOR_START_RUNNING", 2021-26: 0.1858817617}
3: { area: "F15 CMP", dissection_name: "BATCH_WAIT_TIME", 2021-26: 0}
4: { area: "F15 GENERAL", dissection_name: "WAIT_OTHERS", 2021-25: 0.0326702424}
5: { area: "F15 DRY ETCH", dissection_name: "DELIVERY_TIME", 2021-25: 0}
6: {area: "F15 DIFFUSION", dissection_name: "BATCH_WAIT_TIME", 2021-24: 1.544808954}
7: { area: "F15 METROLOGY", dissection_name: "WAIT_FOR_START_RUNNING", 2021-24: 0.0270019481}
8: { area: "F15 PHOTO", dissection_name: "BATCH_WAIT_TIME", 2021-23: 0.0001341795}
9: { area: "F15 DRY ETCH", dissection_name: "DELIVERY_TIME", 2021-23: 0}
最终目标实际上是将转换后的数据加载到一个有角度的ag-grid表中,如下所示:
表的例子:
area dissection_name 2021-24 2021-25 2021-26 2021-27
xxx xxx 0 1.55 2.33 5.3670
xxx xxx xxx xxx xxx xxx
有办法做到这一点吗?由于
您可以使用map
以您想要的形式投影数据:
const finalData = rawData.map((item) => {
const { ww, waiting_time, ...dataItem } = item;
return {
...dataItem,
[ww]: waiting_time
};
});