[更新]:由于JSON数据格式已更改,因此我已删除大部分布局和lodash(失败代码)。lodash通过多个键分组数组
我试图将数据集分组以准备汇总总计。这是传入的JSON布局。我需要组由国家,然后通过品牌:
[
{
$id: "1",
countryCode: "HT",
brand: "CO",
roomNights: 12,
hotelSpend: 2000
},
{
$id: "2",
countryCode: "PK",
brand: "HH",
roomNights: 201,
hotelSpend: 10000
},
{
$id: "3",
countryCode: "RO",
brand: "CO",
roomNights: 34,
hotelSpend: 5000
},
{
$id: "4",
countryCode: "US",
brand: "ES",
roomNights: 120,
hotelSpend: 56000
},
{
$id: "5",
countryCode: "PK",
brand: "HH",
roomNights: 145,
hotelSpend: 33000
}
]
的数据需要被转化成这种格式:
['Brand','HT' , 'PK' , 'US' , 'RO', 'Avg Rm', 'Avg Spend']
['HH' ,'0/0' ,'201/10000', '0/0' , '0/0' , 201, 10000],
['CO' ,'12/2000','0/0', , '0/0' , '34/5000', 23 , 3500],
['ES' , '0/0' ,'0/0' , '120/50000' , '0/0' , 120, 50000]
的roomNights和hotelSpend将每个品牌&全国范围内总计和平均每个都需要在最后计算字段。
谢谢!
我想帮忙,但我无法确切地告诉你在找什么。你能发表一个你希望得到的输出的例子吗? – 2015-02-14 07:57:07
我可以在纯js中做到这一点,但我想这不是你要找的 – taesu 2015-02-16 05:39:56
我对它开放。无论更轻:-) @taesu – 2015-02-16 17:53:30