PDA

View Full Version : How to delay a return statement AND a function call until the data is loaded?



Ppecher
21 Feb 2011, 10:13 AM
connectLoadRenderStoreAndGetCheckBox: function () {
this.someStore = new Ext.data.Store({
proxy:
reader:
]),
sortInfo: { field: , direction: }
});

this.someStore.load(
{
params:
{

}
});
//I left out parameters; lets assume they are valid and work.
this.someStore.on("load", this._renderColumns, this);
return ([this._getCheckBox()]);
} On 'load' I want to both execute the function this._renderColumns (which uses the data from the server) and also return a checkbox (which also uses data from the server). What is a quick & easy way to only return the checkbox after the data is loaded?

21 Feb 2011, 10:56 AM
you don't delay a return statement. You simply have a 'load' event listener for your store that does what you need it to do. You have to think asynchronous. Look it up and you'll find tons of stuff that explains how AJAX communication works.

Ppecher
21 Feb 2011, 11:14 AM
Yes, it would be a good idea to just add a simple listener. However, all of the code is already built on the idea of the function returning that checkbox object. So, I have to somehow find a way to return only after I have the data.

21 Feb 2011, 11:17 AM
You can't!


I think you need to reevaluate your approach :(

Ppecher
21 Feb 2011, 11:42 AM
An items option of a tabpanel (in my extending class) calls the following:


getFilledTable: function () {
this.aStore1 = new Ext.data.Store({
proxy:,
reader:,
sortInfo: { field: , direction:}
//I removed the values
});
return this.aStore1.on('load', this.neExperiment(), this);
},

neExperiment: function (){
this.aGrid1 = new Ext.grid.GridPanel({
store: this.aStore1,
//I removed some other options
});
return this.aGrid1;
}

Is this valid syntax?

21 Feb 2011, 11:44 AM
You're returning the result of the listener registration. Also "this.neExperiment()" is Executing that method.



return this.aStore1.on('load', this.neExperiment(), this);



I think you need to read up on JavaScript too :(