现在有一份这样得数据:
{
"code": 0,
"msg": null,
"data": {
"columns": [{
"columnCode": "ID",
"columnType": "STRING"
}, {
"columnCode": "DATE",
"columnType": "DATE"
}, {
"columnCode": "OIL",
"columnType": "NUMERIC"
}, {
"columnCode": "GAS",
"columnType": "NUMERIC"
}],
"rows": [
["1", "2022-08-08 14:25:05", 23.123, 12.123],
["2", "2022-08-09 14:25:24", 14.123, 45.123],
["3", "2022-08-10 14:25:44", 15.123, 16.123],
["4", "2022-08-11 14:25:05", 12.123, 16.123],
["5", "2022-08-12 14:25:05", 15.123, 24.123],
["6", "2022-08-13 14:25:05", 16.123, 23.123]
]
}
}
希望通过一个方法组织成这样一个数据:
可以看到得规律是:columns是表头,rows是表体。但是表体与表头对应关系为表体得下标。表头得对应字段是columnCode;
怎么实现?
[
{"ID": "1", "DATE": "2022-08-08 14:25:05", "OIL":23.123, "GAS": 12.123 },
{"ID": "2", "DATE": "2022-08-09 14:25:24", "OIL":14.123, "GAS": 45.123 },
...
]
以此类推。求一个方法实现这个功能!
js
代码结果