PDA

View Full Version : autoLoad callback / success handler



djfiii
3 Apr 2008, 4:42 AM
Let's say I have a tab panel and I have the following addTab method:


addTab: function(tp,title,url,closable,tabLoadCallback){
this.tp.add({
title: title,
iconCls: 'tabs',
autoLoad: {
url: url,
callback: tabLoadCallback
},
closable:closable
}).show();
},


my goal is to act on the loaded content with EXT. I'm looking for the equivilant of Ext.onReady for AJAX loads. If I try to Ext.get a div that loads, and render something to it, it doesn't exist yet. I thought callback only fired after the load completed? Any tips appreciated!

evant
3 Apr 2008, 4:47 AM
It does only fire after the callback has been completed. The callback may not have been successful.

djfiii
7 Apr 2008, 5:40 PM
evant, thanks for the reply.

I'm calling the addTab method as follows:


onClick="IGS.app.addTab(IGS.app.tabs,'<%= fID %>','findings-detail.asp?fID=<%= fID %>',true,IGS.app.loadFindingsDetail());"

You can see the last argument is the callback, which in this case happens to be IGS.app.loadFindingsDetail()

Now, just to test, in loadFindingsDetail() I'm doing the following:


loadFindingsDetail: function(){
var fd = Ext.get("fDetail");
alert(fd);
/*
var p = new Ext.Panel({
title: 'Fit Layout',
renderTo: fd,
layout:'fit',
items: {
title: 'Inner Panel',
html: '<p>This is the inner panel content</p>',
border: false
}
});
*/

},

you can see the first thing I'm doing is trying to get reference to an element with id "fDetail". this is a div that is loaded in the content of the tab that is added. I'm getting an alert box with "null" - this occurs before the new tab renders, so not surpisingly it's giving me null because "fDetail" doesn't exists yet. It seems the callback is executing before the content is loaded and the new tab is rendered. Any ideas why that might be?

evant
7 Apr 2008, 5:46 PM
Ah.

You aren't passing the callback correctly:



addTab(..., IGS.app.loadFindingsDetail()) //executes IGS.app.loadFindingsDetail and returns the result. The result will be passed as the callback

addTab(..., IGS.app.loadFindingsDetail) //passes a reference to the function.

djfiii
8 Apr 2008, 8:25 AM
of course :) thanks a bunch for pointing that out!