我正在努力订购 JavaScript 对象。这是我必须排序的数据部分。
我想将每个对象分组ParentMemberCode
,然后按Order
.
{
"MemberCode": "B1G",
"ParentMemberCode": "B1_GA",
"MemberName": "Gross value added at basic prices, total activity",
"Order": 1
},
{
"MemberCode": "P119",
"ParentMemberCode": "B1_GA",
"MemberName": "Financial Intermediation Services Indirectly Measured (FISIM)",
"Order": 2
},
{
"MemberCode": "B1G_P119",
"ParentMemberCode": "B1_GA",
"MemberName": "Gross value added at basic prices, excluding FISIM",
"Order": 3
},
{
"MemberCode": "D21_D31",
"ParentMemberCode": "B1_GA",
"MemberName": "Taxes less subsidies on products",
"Order": 4
},
{
"MemberCode": "B1_GE",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product - expenditure approach",
"Order": 1
},
{
"MemberCode": "GDP",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product",
"Order": 1
},
{
"MemberCode": "B1_GI",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product - income approach",
"Order": 2
},
{
"MemberCode": "B1_GA",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product at market prices - output approach",
"Order": 3
}
我想像这样重组和排序数据:
{
"MemberCode": "GDP",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product",
"Order": 1
}
{
"MemberCode": "B1_GE",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product - expenditure approach",
"Order": 1
},
,
{
"MemberCode": "B1_GI",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product - income approach",
"Order": 2
},
{
"MemberCode": "B1_GA",
"ParentMemberCode": "GDP",
"MemberName": "Gross domestic product at market prices - output approach",
"Order": 3,
[
{
"MemberCode": "B1G",
"ParentMemberCode": "B1_GA",
"MemberName": "Gross value added at basic prices, total activity",
"Order": 1
},
{
"MemberCode": "P119",
"ParentMemberCode": "B1_GA",
"MemberName": "Financial Intermediation Services Indirectly Measured (FISIM)",
"Order": 2
},
{
"MemberCode": "B1G_P119",
"ParentMemberCode": "B1_GA",
"MemberName": "Gross value added at basic prices, excluding FISIM",
"Order": 3
},
{
"MemberCode": "D21_D31",
"ParentMemberCode": "B1_GA",
"MemberName": "Taxes less subsidies on products",
"Order": 4
},
]
}
这对我来说真的很复杂,所以我需要你的帮助。你对此有什么想法吗?
请不要使用 underscore.js 限制您的想法。