PDA

View Full Version : adding items



newusername
24 Feb 2013, 8:37 AM
Hi,

I have simple code written in ext js 3.4



Ext.onReady(function()
{
var myForm = Ext.extend(Ext.FormPanel,{
width : 100,
height : 200,
items : [
{
fieldLabel : 'First Name',
xtype : 'textfield',
name : 'FName',
allowBlank : false
}


],
initComponent: function(){
this.title = 'Login Form';
/*this.items : [ {
fieldLabel : 'First Name',
xtype : 'textfield',
name : 'FName',
allowBlank : false
}


];*/
myForm.superclass.initComponent.call(this);
}


});



var f = new myForm();
f.render(document.body);
});


In this code 'items' property is added outside of initComponent function. If I add same property within initComponent and uncomment the code then component is get rendered. I really not able to understand what is happening here..

sword-it
26 Feb 2013, 9:02 AM
We do not support putting complex objects in the prototype of an extended class. When you do this, the objects will be shared across instances of classes and in essence become static.

Prior to calling the parent class's initComponent method you can view what is in this. items.

After invoking the parent class's initComponent method you can view what is in this.items

You would never be able to set the "Property" items directly.
You can invoke the "Method" add after the component is setup.

Check this link for more details:-
http://www.sencha.com/forum/showthread.php?106961-Where-to-add-Items-array-to-an-extended-Panel-Class