Elie Saad Elie Saad - 10 months ago 86
Javascript Question

JSLINQ groupBy error

I am trying to manipulate a json file, so I am trying JSLINQ, but I can't figure out why I hit an error at groupBy().
The website that led me to this code.

var query = JSLINQ(json);
var result = query.groupBy(function (i) { //HERE is where the error hits.
return i.CustomerName; //Attribute of json
.select(function (i) {
return {
CustomerName: i.Key, data: i.elements //I read that I get groupBy result like this.
.select(function (j) {
x = j.x, y = j.y //x and y are attributes

query.groupBy is not a function

War War

Ask and ye shall receive young padawan ...

var result = jslinq(data)
   .groupBy(function (i) { return i.CustomerName; })
   .select(function(g) {
      return {
         key: g.key,
         items: jslinq(g.elements).select(function(i) { return { x: i.x, y: i.y } }).items



Key differences between yours and mine ...

  • jslinq has been lowered in the version listed on github
  • element collections in the groups need to be wrapped in jslinq() too to be queried