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 でアイデアを制限しないでください。