PDA

View Full Version : set property of a private object



alberto01
23 Sep 2010, 9:36 AM
Hello I have this code:


End.app = (function(){
var pp = new Ext.Panel({
title: 'FINE!',
autoHeight: true,
padding: 10,
margin: 20,
id: 'disclaimer',
frame:true,
contentEl: 'disclaimerContent' // <---- no access to DOM
});
return {
init: function() {
pp.render('content-inside');
}
}
})();

I need to render the panel at the end of a function. And that' s ok.
When i call: End.app.init it -obviously- doesn't show anything because the 'pp' does not have access to the DOM.

How can I set the property contentEl in the init method? The Panel object does not have a public metho to set it... ?

thansk!
BYE

plalx
23 Sep 2010, 10:41 AM
The DOM is always accessible from any scopes because the document variable is public.
However, you might experience some errors if you try to access DOM elements before the document is ready.

Make sure you are calling the init() function only when the document is ready using Ext.onReady() function.

It could look like this:


Ext.onReady(End.app.init);

*Note: I am not sure at what stage the panel will try to gather the contentEl element. If it tries to store the reference to it right after instantiation, you will have to move your panel instantiation code inside the init() function.

alberto01
23 Sep 2010, 10:55 AM
Actually I dont call the End.app.init because if I call it, it will render an empty panel over the 'content-inside' div at the startup...
I need to render the panel from another module...
Something like


step1.destroy();
End.app.init();


btw, the problem is not on the 'render' method, the problem is in the contentEl: 'disclaimerContent'.
It can't take any information from the DOM until it (the dom) does not exist...

.... o not? :P