Archive for extjs

callback function was triggered before store finished loading

A javascript error: data store contains undefined data.
It seems that the callback function has been invoked before store data comes back from server. The problem is because when the server has not cached the result for the very first time, it will timeout the request. And the timeout of the connection provided to the HttpProxy was at the default value of 30 seconds, by increasing the value will prevent the error happening.

Solutions:
———-
1. In the store definition:

proxy: new Ext.data.HttpProxy({
  url: 'myurl',
  method: "GET",
  timeout: 90000  // milliseconds
})

2. Actually for all the ajax timeout value, on the same web page, could be set as the following:
Ext.Ajax.timeout = 90000;

3. Check the result before further manipulation of the returned store data
mystore.load({params: {param_name: param_value},
callback: function(records, options, success)
{
  if (success && records[0] != undefined)
  {
    // manipulate the data
    var example = records[0].get('item');
  }
}

Comments