Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:35:55+00:00 2026-06-12T20:35:55+00:00

I have a JSON store : { Week: 1145, From: IN1 }, { Week:

  • 0

I have a JSON store :

{
    "Week": 1145,
    "From": "IN1"
},
{
    "Week": 1145,       
    "From": "IN1"
},
{
    "Week": 1145,        
    "From": "IN2"
},
{
    "Week": 1146,
    "From": "IN1"
},
{
    "Week": 1146,
    "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:

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:35:56+00:00Added an answer on June 12, 2026 at 8:35 pm

    You need to pass From as parameter too.

    Try below:

    countBy: function(param, param2){
        var count = {};
        this.each(function(item){
            var type = item.get(param);
            var from = item.get(param2);
            if (type in count){
                if (from in count[type]) {
                  count[type][from]++;
                } else {
                  count[type][from] = 1;
                } 
            } else {
                count[type] = {};
                count[type][from] = 1;
            }                               
        });
        return count;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Javascript I want to have a JSON or array that will store id
I have a list reading from a Json store which contains a grouper on
I have localized resx files that I want to convert to JSON and store
I have a json object I want to store in my db: $string='{test: [{name:dave,user:dan}]}';
I have a JSON data store used for a combobox selection which is working
How to store large JSON String in cookie ? I have to use cookie
I have JSON string that has nested objects with dynamic names that vary each
following extjs3 problem: i have an json store: dbStore = new Ext.data.JsonStore({ url: '/?[action]=getFormData',
I am generating data in a grid panel using json store. I have to
I have some JSON objects I'd like to store in a map for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.