PDA

View Full Version : Function that is ran after data is loaded with Ext.data.store



djudjublondin
31 Aug 2007, 12:34 AM
Hi,

I am having difficulties the "load()" function of an Ext.data.Store object.
Let say that


ds = new Ext.data.Store(
{
proxy: proxy,
reader: reader,
}
);
I would like to perform an action using a function of my own called "buildNodeInfo()" when data loading is finished. So far I have tried two way of implementing it with no success:


ds.on('load', buildNodeInfo()); //method 1

and


ds.load({
callback : buildNodeInfo() //method 2
});
both of these method ran the function "buildNodeInfo()" before the end of the loading process (which can last 4 sec sometimes).
Does anyone has clue ?

Cheers

Dju

Animal
31 Aug 2007, 12:37 AM
Bound to isn't it?

The statement "buildNodeInfo()" calls the function buildNodeInfo.

djudjublondin
31 Aug 2007, 5:27 AM
Indeed the statement "buildNodeInfo()" calls the function buildNodeInfo which actually take a value from the data store in order to display it into a div ( using "ds.getAt(0).data.node_title").
The fact is that I don't know from API documentation how to properly use callbacks with ds.load() or if other events than "load" would be more appropriate (like "afterload" for exemple, apparently this one does not exits).
By the way Animal thank you very much for your answer, however I did not understand what you meant by "Bound to it".

Cheers

Dju

BernardChhun
31 Aug 2007, 5:33 AM
oyo Dju,

your callback is called immediately because you added those parenthesis :)

a function in javascript is also an object so you may pass them as is:


ds.on('load', buildNodeInfo, this, true); // no parenthesises!!

the callback will then be parenthesised(called, raised) by Ext at the right moment ~o)

djudjublondin
31 Aug 2007, 6:33 AM
Thank you very much for your help bernard !!!

Dju