PDA

View Full Version : Unable To Loop Through Store



rnxfod
29 Nov 2013, 2:48 AM
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.


//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.

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.

evant
29 Nov 2013, 2:57 AM
Store loading is asynchronous, you need to wait until the store loads. Listen to the load event before doing any processing.