My data consists of JSON objects with "Week" and "From" properties:
{
"Week": 1145,
"From": "IN1"
},
{
"Week": 1145,
"From": "IN1"
},
{
"Week": 1145,
"From": "IN2"
},
{
"Week": 1146,
"From": "IN1"
},
{
"Week": 1146,
"From": "IN2"
}
I am trying to count the occurrences of each value in "From" for a given "Week". For example, for Week 1146, I would like to get IN1 = 1 and IN2 = 1, and for week 1145, IN1 = 2 and IN2 = 1.
I have created a function that iterates through my data store to tally up the occurrences of values based on a specified parameter:
countBy: function(param){
var count = {};
this.each(function(item){
var type = item.get(param);
if (Ext.isDefined(count[type])){
count[type]++;
} else {
count[type] = 1;
}
});
return count;
}
However, when I provide "Week" as the parameter, the function does not calculate the counts of distinct values in "From" for each WEEK; instead, it aggregates all occurrences under each week. For instance, it returns 1145 : 3 and 1146 : 2, while the desired outcome is 1145 : {IN1 : 2} and 1146 : {IN1 : 1}.
Your assistance in solving this issue would be greatly appreciated!