javascript - linqjs group by with a sum -
this might seems easy question i'm struggling linqjs syntax.
given following basic json:
{ "dateevent": "2013-04-23 14:00:00z", "daterecord": "2013-04-23 14:00:00z", "amount": -9500, "type": { "description": "capital" }, "currency": { "id": "usd", } }
using linqjs how can return total each currency?
enumerable.from(data) .groupby("{ currency: $.currency.id }", null, function (key, g) { var result = { currency: key.currency, total: g.sum($.amount) }});
the code above doesn't work.
you had it. key selector in groupby , sum incorrect. key selector needs string. try following:
var result = enumerable.from(data).groupby("$.currency.id", null, function (key, g) { var result = { currency: key, total: g.sum("$.amount") } return result; }).toarray();
Comments
Post a Comment