我正在尝试操作json文件,所以我正在尝试JSLINQ,但我无法弄清楚为什么我在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) {
console.log(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
})
}
}).toArray();
query.groupBy不是函数
答案 0 :(得分:2)
要求你们接受年轻的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
};
})
.toList();
console.log(result);
...
你和我之间的主要区别......