I'm trying to get the component in which a menu is linked. Take a look:
Ext.create('Ext.Button', {
id: 'MyButton',
text: 'Click me',
renderTo: Ext.getBody(),
menuAlign: 'tl-bl',
menu: {
itemId: 'MyMenu',
forceLayout: true,
items:
[
{
text : 'Option 1',
itemId: 'MyItemMenu1'
}, {
text : 'Option 2',
itemId: 'MyItemMenu2'
}, {
text : 'Get the parent!',
itemId : 'MyItemMenu3',
handler: function(){
// Get the item menu.
var MyItemMenu3 = this;
alert(MyItemMenu3.getItemId());
// Get the menu.
var MyMenu = MyItemMenu3.ownerCt;
alert(MyMenu.getItemId());
// Try to get the button.
var MyButton = MyMenu.ownerCt;
alert(MyButton);
// Returns:
// 'MyItemMenu3'
// 'MyMenu'
// undefined
}
}
]
}
});
Online example: http://jsfiddle.net/RobertoSchuster/mGLVF/
Any idea?
I'm learning EXT myself so I'm not too sure what's going on but I think I was able to get it this way: console.log(MyMenu.floatParent.id)
;
In our ExtJS 4 project, we eventually just patched the up()
function on AbstractComponent
Ext.AbstractComponent.override({
up: function(selector) {
var result = this.ownerCt||this.floatParent;
if (selector) {
for (; result; result = result.ownerCt||result.floatParent) {
if (Ext.ComponentQuery.is(result, selector)) {
return result;
}
}
}
return result;
}
});
This makes up()
walk up the ownerCt
chain, but if ownerCt
isn't defined, it looks to floatParent
.
Now you can call cmp.up('some-selector');
even if its a menu or menu item.
Try this:
Ext.getCmp('My-Button').menu.refOwner
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With