I have a JSON store :
Code:
{
"Week": 1145,
"Sev_Logged": 22,
"From": "IN1"
},
{
"Week": 1145,
"Sev_Logged": "44",
"From": "IN1"
},
{
"Week": 1145,
"Sev_Logged": 54,
"From": "IN2"
},
{
"Week": 1146,
"Sev_Logged": "66",
"From": "IN1"
},
{
"Week": 1146,
"Sev_Logged": "66",
"From": "IN2"
}
I want to count for each "Week", the number of "From", for example for Week 1146, i'd get IN1 = 1 and IN2 = 1 and for week 1145 i'd get IN1 = 2 and IN2 = 1.
I've written a function that loops through my data store to count IN1 and IN2 for each param:
Code:
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;
}
But the problem is that when I give it "Week" in param, it doesn't count IN1 and IN2 for each WEEK, it returns "1145" : 3 and 1146 : 2, but what i want is : "1145" : {IN1 : 2} and "1146" : {IN1 : 1}.
Thank you for your help!