Results 1 to 2 of 2

Thread: Unable To Loop Through Store

  1. #1
    Sencha User
    Join Date
    May 2013
    Location
    Ghana
    Posts
    11
    Answers
    1

    Default Answered: Unable To Loop Through Store

    Hello,

    Need help figuring out what's wrong with my code. I have store that am able to load in to a grid, this works perfectly fine.

    Code:
    //populate Units Sections grid with selected index
    var record_id = form.getForm().getValues().dept_id;
    var units_store = Ext.create('SmartHR.store.entities.UnitsStore');
    units_store.getProxy().url = '/service/admin/mastersetup/selectall/Hrp_units/by/dept_id/' + record_id
    units_store.load();
    Ext.getCmp('units_grid1').reconfigure(units_store);
    problem is, now I want to loop through on of the columns in the store (no_of_employees) but it doesn't work.
    Even placed a console.log in the iteration but it never outputs.
    Code:
    var employee_numbers = [];
    var number_of_employees = 0;
    units_store.each( function(rec) {
        console.log(rec.get('no_of_employees'));
        number_of_employees += rec.get('no_of_employees');
        employee_numbers.push(rec.get('no_of_employees'));
    });
    Thanks in advacnce.

  2. Store loading is asynchronous, you need to wait until the store loads. Listen to the load event before doing any processing.

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,245
    Answers
    758

    Default

    Store loading is asynchronous, you need to wait until the store loads. Listen to the load event before doing any processing.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •