PDA

View Full Version : How get component of another container (without using getCmp)?



bryan10
31 Jan 2012, 11:27 PM
Hello,
I have some code below which shows a window (container)
containing a button ('Click3') and a panel. The panel
contains a button ('Click') and a tbar. The tbar contains
a button ('Click2') and a combo.


I require to get the value selected in the combo following
clicking on any of the buttons Without using Ext.getCmp(),
and without any component having an id (an itemId is ok).


I do not know how to get the combo component.


Ext.getCmp('<comboid>') would work but requires combo
to have id.


I am looking for something similar to:
btn.up('window/panel').getComponent('<comboItemId>');


Please would you be able to answer?


I have placed '// soln???' in code where a solution is required.


Thank you,
Bryan



Ext.Loader.setConfig({enabled:true});


Ext.define('BILL.view.ListPage' ,{
extend: 'Ext.panel.Panel',
alias : 'widget.listpage',
tbar: [
{
xtype: 'combo',
store : [ 'Spencer', 'Maintz', 'Avins' ],
itemId: 'empcombo',
fieldLabel: 'Emp',
mode : 'local'
},
{
xtype: 'button',
text : 'Click2',
width: 100,
handler: function(btn) {
// soln???
// var v = btn.up('panel').getComponent('empcombo');
// console.log('v '+v);
}
},
],
items: [
{
xtype: 'button',
text: 'Click',
handler: function(btn) {
// soln???
}
}
]


});


var win = Ext.create('Ext.Window', {
minHeight: 400,
minWidth: 350,
alias: 'widget.win',
items: [
{
xtype: 'button',
text: 'Click3',
width: 100,
itemId: 'c3',
handler: function(btn, e) {
// soln???
}
},
{
xtype: 'listpage',
width: 400
},
],
});


Ext.application({
launch: function() {
win.show();
}
});

tvanzoelen
1 Feb 2012, 12:12 AM
component.query("#" + itemId);

friend
1 Feb 2012, 6:47 AM
@bryan10:

Keep in mind that query() returns an array, so using tvanzoelen's example, you'd need to do this:



var targetComponent = component.query("#" + itemId)[0];


To find a component anywhere in your app, from anywhere in your app:



var targetComponent = Ext.ComponentQuery.query('#' + itemId)[0];



An alternative method is available, where it only returns the first object which matches your selector:



var targetComponent = component.down('#' + itemId);