PDA

View Full Version : Navigation components | | How to do without component ID?



mbvana
29 Dec 2011, 4:59 AM
I could never understand how to find some components if I can not set the ID for it?
For example, I have a grid-component with toolbars


Ext.define ('AM.view.user.List', extend: 'Ext.grid.Panel',...
tbar: [
{ text: 'Add', action: 'add' },
{ text: 'Edit', action: 'edit' }...]
...

In the controller, I define


Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
views: [ 'user.List', 'user.Edit' ],
..........
someFunction: function(){
var view = Ext.widget ('userlist'); /* here i want find the ADD-button */
}

How can to find buttons?
How can to find some component (e.g. button) if parent component is composed of multiple nested panels?
Thank you very much

scottmartin
29 Dec 2011, 9:29 AM
Assign 'itemId' to your button, then use view.down('#myitemid') to access the control.

You can use up()/down() to search for components.

Regards,
Scott.

mitchellsimoens
29 Dec 2011, 9:31 AM
You can use up()/down() to search for components.

And query if you want an array of matches :)

mbvana
29 Dec 2011, 11:50 PM
Thanks


Assign 'itemId' to your button, then use view.down('#myitemid') to access the control.
I'm thinking it's wrong to attache to ID. I have a lot of insteads of this component. I'm wrong?


You can use up()/down() to search for components.
I don't understand. up/down "Selects a single child ... based on the passed CSS selector ". But i want to select button as Ext-component. No as some DOM-element.
May be I must button as DOM-element, then find its wrappers div with ID of button-component, then make getCmp(..)???
THere is not more short a way? May be with ComponentMgr?

mbvana
30 Dec 2011, 12:23 AM
I solved the problem this way:


Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
......
myBtns:[], // buttons of View
init: function() {
this.control({
'userlist button[action=add]': {
click: this.add,
afterrender:this.regBtn // there I reg this button
},
............................
},
getBtn:function(obj){
this.myBtns.push(obj); // there I reg all buttons
}

But I don't now it's a good way

mitchellsimoens
30 Dec 2011, 6:07 AM
up/down/query on an Ext.Element does use a CSS selector. However on a Component it uses ComponentQuery