I have the following array:
var source = [
{ "DistributorId": 1, "DistributorName": "Distributor 01", "PriceListId": 1, "Year": 2014, "Month": 9 },
{ "DistributorId": 1, "DistributorName": "Distributor 01", "PriceListId": 2, "Year": 2014, "Month": 10 },
{ "DistributorId": 2, "DistributorName": "Distributor 02", "PriceListId": 3, "Year": 2014, "Month": 10 },
{ "DistributorId": 3, "DistributorName": "Distributor 03", "PriceListId": 4, "Year": 2014, "Month": 9 },
{ "DistributorId": 3, "DistributorName": "Distributor 03", "PriceListId": 5, "Year": 2014, "Month": 10 }
];
I want to to use linq.js to group these array by two fields "DistributorId" and "DistributorName" to get the following result:
var des =
[
{
"DistributorId": 1,
"DistributorName": "Distributor 01",
"PriceLists":
[
{ "Year": 2014, "Month": 9 },
{ "Year": 2014, "Month": 10 }
]
},
{
"DistributorId": 2,
"DistributorName": "Distributor 02",
"PriceLists":
[
{ "Year": 2014, "Month": 10 }
]
},
{
"DistributorId": 3,
"DistributorName": "Distributor 03",
"PriceLists":
[
{ "Year": 2014, "Month": 9 },
{ "Year": 2014, "Month": 10 }
]
}
];