PDA

View Full Version : Get items property after component been created



wallynm
27 Jan 2012, 12:29 PM
Well guys, i'm building form generator which i need to insert dynamic components to a panel, component as textfield, textareas, an etc. My question is:


There is a way to retrieve item property?
Example: When we create a new panel, we use this markup...
Ext.create('Ext.panel.Panel', {
title: 'Simple panel',
height: 300,
width: 300,
items:[{
// Here we put other components, and my forms will be added here
}]
})

There's a way to get the items property that i had setted on creation? (and updated it on the fly)

friend
27 Jan 2012, 12:45 PM
Ext.ComponentQuery.query('<some CSS-like selector here>') is the way to go. You should consider at least providing your panel with an itemId attribute, like so:



Ext.create('Ext.panel.Panel', {
title: 'Simple panel',
itemId: 'targetPanel',
height: 300,
width: 300,
items:[{
// Here we put other components, and my forms will be added here
}]
})


You could then do things like this:



var targetComponent = Ext.ComponentQuery.query('#targetPanel')[0].down('textarea');

skirtle
28 Jan 2012, 11:42 AM
The items config option get converted into a MixedCollection containing the child components. This only happens at instantiation time. If you need to add child components later you have to use a suitable method on the container instead:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.container.Container-method-add
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.container.Container-method-insert


var panel = Ext.create('Ext.panel.Panel', {
title: 'Simple panel',
height: 300,
width: 300,
items:[
...
]
});

panel.add({
xtype: 'textfield',
...
});