I am currently working with extjs 4.2 and I have encountered a situation where I am loading the store object in the following manner:
var userDetailStore = Ext.create('Ext.data.Store', {
model: 'Person.DetailsModel',
autoLoad: true,
proxy: {
type: 'ajax',
method: 'POST',
url: 'getValueAction.action',
reader: {
type: 'json',
root: 'details'
},
writer: {
type: 'json',
root: 'details'
}
},
fields: ['id', 'loginName', 'referenceId', 'name']
}); // Here I load the store which will definitely contain a list of values.
Following the store creation, I attempt to retrieve the referenceId of the first value from the store object using this code:
var empId = userDetailStore.getAt(0).get('referenceId');
However, I encounter an error because at that point, the getCount() function of the userDetailStore object is returning zero. Interestingly, if I include an alert('loading data'); statement before retrieving the referenceId, the code works as expected. The line userDetailStore.getCount() returns the correct count.
It seems like there may be a timing issue between loading the store and accessing it, but I would prefer not to rely on alert statements for this. I have tried using the sleep() method instead of alert, but that did not resolve the issue either (and I don't want to freeze the browser with sleep()).
Am I missing something in how I'm loading the store? Is there a standard way to ensure my code runs after the store has completely loaded?
If anyone could provide some guidance, I would greatly appreciate it.
Regards, Dev