PDA

View Full Version : Why can't I add items to a panel after Ajax call?



tryingextjs
10 Mar 2010, 7:04 AM
On a tab change, I need to retrieve some data and then add items to the tab based on the ajax request results. I'm finding that I can add items in the event handler but not in the ajax success function even though I can still get reference to the container tab. Am I missing some sort of rendering step? My code is below. Suggestions are appreciated.



var tabs = new Ext.TabPanel({
region: 'center',
id: 'center-panel',
deferredRender: false,
activeTab: 0,
items: [panel1, panel2],
listeners: {
'tabchange': function(tp, currentTab) {
if (currentTab) {
if (currentTab == panel2)
Test(panel2);
}
}
}
});

function Test(parentItem) {
//can add items here without a problem
Ext.Ajax.request({
method: 'GET',
url: "getdata.php",
success: function(response) {
//cannot add items here
alert(parentItem.id); //still have the correct parentItem
parentItem.add({ title: 'test', html: 'body' }); //doesn't work
Ext.getCmp('cp1').add({ title: 'test', html: 'body' }); //doesn't work
},
failure: function(a) { alert(JSON.stringify(a)); }
});
}

Animal
10 Mar 2010, 7:48 AM
What do the notes in the API description for Container.add tell you?