PDA

View Full Version : Use of Render/ Ext.getBody()



rishu1210
6 Jan 2013, 11:54 AM
Hi All,

Hope you are all doing good.

I am new in ext-js 4. I have some queries during examples.

app.js


Ext.application({
name : 'MyApp',
requires : ['Ext.window.MessageBox', 'MyApp.view.Student'],


launch : function() {
var student = Ext.create('MyApp.view.Student', {
id : 'The Portal'

});
student.render(Ext.getBody())
//console.log(student.getId());
}
});




and Student.js



Ext.define('MyApp.view.Student', {
extend : 'Ext.Component',
config : {
id : ''
},
constructor : function(config) {
this.initConfig(config);
}
});




In my above example, I want to display id of student on the page..How can i do that ?
and don't know proper use of renderTo/ Ext.getBody() method,
and during run this program i get following error :

"Uncaught TypeError: Cannot read property 'beforerender' of undefined ";

Please guide me..

Thanks :)

scottmartin
7 Jan 2013, 7:10 PM
You should not be setting the id to '', or with spaces. It is recommended that you do not set id at all and let the id gen automatically.

I would suggest using itemId and then use componentQuery to get access:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ComponentQuery

panel.down('#panel-itemid')

As for the render .. if you are rendering to the body, then:

renderTo: Ext.getBody(), or renderTo: document.body

Typically would would render a viewport (auto render to body) or render a panel to the body and they draw the component in the panel.

Scott.