这是我的数据格式:
[{city:"Bhopal",id: 1},{city:"Bhopal",id: 2},{city:"Delhi",id: 3},{city:"Delhi",id:3}]
这里我有德里重复两次同样的身份。
现在我需要明确计算城市,其中 id 是不同的,例如:
[key:"Bhopal",value:2, key:"Delhi",value:1]
其中值为计数
答案 0 :(得分:0)
使用Reductio和Crossfilter获得答案。
var payments = crossfilter([
{city: "Bhopal", id: 1},{city: "Bhopal", id: 2},{city: "Delhi", id: 3},{city: "Delhi", id: 3}
]);
var dim = payments.dimension(function(d) { return d.city; });
var group = dim.group();
var reducer = reductio()
.exception(function(d) { return d.id; })
.exceptionCount(true);
reducer(group);
console.log(group.top(Infinity));
输出:[{key:'Bhopal',value:{exceptionCount:2},{key:'Delhi',value:{exceptionCount:2}]