【发布时间】:2025-08-29 15:45:02
【问题描述】:
我有一组对象
[
{
Severity: "<span class='tableActive'></span>",
Name: 'U3B',
'U1A_Shift SCM: UPTT-Pressure (Bara)': '-',
'U1A_Shift SCM: DPTT-Pressure (Bara)': '-',
'U3B SCM: APTT-Pressure (Bara)': '3510.00',
'U3B SCM: UPTT-Pressure (Bara)': '3413.00',
'U1B SCM: DPTT-Pressure (Bara)': '-',
'U1B SCM: UPTT-Pressure (Bara)': '-',
'U3B SCM: DPTT-Pressure (Bara)': '740.00',
'U1A_Shift SCM: UPTT-Temp (DegC)': '-',
'U1A_Shift SCM: DPTT-Temp (DegC)': '-',
'U3B SCM: APTT-Temp (DegC)': '1565.00',
'U3B SCM: UPTT-Temp (DegC)': '2654.00',
'U1B SCM: DPTT-Temp (DegC)': '-',
'U1B SCM: UPTT-Temp (DegC)': '-',
'U3B SCM: DPTT-Temp (DegC)': '3159.00',
'U1B SCM: PCV-CHOKE status - Control position': '-',
'U3B SCM: PCV-CHOKE status - Control position': '-',
'U1A_Shift SCM: PCV-CHOKE status - Control position': '-',
Alarms: 0,
Advisories: 0,
__row_index: 0,
},
]
因此输出应该是
[
{
Severity: "<span class='tableActive'></span>",
Name: 'U3B',
'U1A_Shift SCM: UPTT-Pressure (Bara)': '-', // grouped by UPTT-Pressure (Bara)
'U3B SCM: UPTT-Pressure (Bara)': '3413.00',
'U1B SCM: UPTT-Pressure (Bara)': '-',
'U1A_Shift SCM: DPTT-Pressure (Bara)': '-', //grouped by DPTT-Pressure (Bara)
'U1B SCM: DPTT-Pressure (Bara)': '-',
'U3B SCM: DPTT-Pressure (Bara)': '740.00',
'U3B SCM: APTT-Pressure (Bara)': '3510.00', // grouped by APTT-Pressure (Bara)
'U1A_Shift SCM: UPTT-Temp (DegC)': '-', // grouped by UPTT-Temp (DegC)
'U3B SCM: UPTT-Temp (DegC)': '2654.00',
'U1B SCM: UPTT-Temp (DegC)': '-',
'U1A_Shift SCM: DPTT-Temp (DegC)': '-', // grouped by DPTT-Temp (DegC)
'U1B SCM: DPTT-Temp (DegC)': '-',
'U3B SCM: DPTT-Temp (DegC)': '3159.00',
'U3B SCM: APTT-Temp (DegC)': '1565.00', // grouped by APTT-Temp (DegC)
'U1B SCM: PCV-CHOKE status - Control position': '-', // grouped by PCV-CHOKE status - Control position
'U3B SCM: PCV-CHOKE status - Control position': '-',
'U1A_Shift SCM: PCV-CHOKE status - Control position': '-',
Alarms: 0,
Advisories: 0,
__row_index: 0,
}
]
我需要根据“:”之后的键名对这个对象数组进行排序,例如:APTT-Temp (DegC)
我只列出了我收到的对象数组的单个对象
我需要对这个对象数组进行排序,基本上是按“:”(冒号)后面的key的值来分组
【问题讨论】:
-
这能回答你的问题吗? Sorting an array of objects by object key
-
@biberman : 不
标签: javascript arrays json