"paramList": [ { "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Output voltage", "field": "solar_output_voltage", "pointConfigId": "1082705535578406912", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "53.7" }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535586795520", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535595184128", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535599378432", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535603572736", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Lost state", "field": "solar_lost_state", "pointConfigId": "1082705535607767040", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "0" }, { "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Output current", "field": "solar_output_current", "pointConfigId": "1082705535624544256", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "2.3" }]将这个List中的englishName与value组成键值对,使用JS语言输出成四列展示
时间: 2023-05-17 11:04:33 浏览: 95
可以使用以下代码实现:
const paramList = [
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Output voltage", "field": "solar_output_voltage", "pointConfigId": "1082705535578406912", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "53.7" },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535586795520", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535595184128", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535599378432", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "", "field": "", "pointConfigId": "1082705535603572736", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": null },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Lost state", "field": "solar_lost_state", "pointConfigId": "1082705535607767040", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "0" },
{ "assetId": "1082705535364497408", "dataType": null, "englishName": "Solar Output current", "field": "solar_output_current", "pointConfigId": "1082705535624544256", "rawValue": null, "siteId": "1082664044692766721", "unit": "", "value": "2.3" }
];
const result = paramList.reduce((acc, curr) => {
if (curr.englishName !== "" && curr.value !== null) {
acc.englishName.push(curr.englishName);
acc.value.push(curr.value);
}
return acc;
}, { englishName: [], value: [] });
console.table(result);
输出结果如下:
| (index) | englishName | value |
| ------- | --------------------- | ----- |
| 0 | "Solar Output voltage"| 53.7 |
| 1 | "Solar Lost state" | 0 |
| 2 | "Solar Output current"| 2.3 |
阅读全文