猿问

萌新求教!JSON数据根据字段分组并排序

[{
"controlGroupId":0,
"controlGroupName":"基础数据",
"controlSortId":0,
"controlType":"CtlComboBoxEdit",
"domain":"CodeAirportAiracType"
},{
"controlGroupId":0,
"controlGroupName":"基础数据",
"controlSortId":2,
"controlType":"CtlComboBoxEdit",
"domain":"CodeAirportAiracType"
},{
"controlGroupId":2,
"controlGroupName":"高级",
"controlSortId":6,
"controlType":"CtlComboBoxEdit",
"domain":"CodeAirportAiracType"
},{
"controlGroupId":2,
"controlGroupName":"高级",
"controlSortId":9,
"controlType":"CtlComboBoxEdit",
"domain":"CodeAirportAiracType"
}]
这是例子真实情况controlGroupId可能有多个不确定的值。举例:controlGroupId为0的分为一组,为2的分为一组,取controlGroupName为组名,并且组之间升序。各组之中再根据controlSortId升序。这个例子期望的结果为
[
{
title:"基础数据",
group:[
{
controlGroupId:0,
controlGroupName:"基础数据",
controlSortId:0,
controlType:"CtlComboBoxEdit",
domain:"CodeAirportAiracType"
},
{
controlGroupId:0,
controlGroupName:"基础数据",
controlSortId:2,
controlType:"CtlComboBoxEdit",
domain:"CodeAirportAiracType"
}
]
},
{
title:"高级",
group:[
{
controlGroupId:2,
controlGroupName:"高级",
controlSortId:6,
controlType:"CtlComboBoxEdit",
domain:"CodeAirportAiracType"
},
{
controlGroupId:2,
controlGroupName:"高级",
controlSortId:9,
controlType:"CtlComboBoxEdit",
domain:"CodeAirportAiracType"
}
]
}
];
繁花如伊
浏览 242回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答