How to get the parent of a menu?

Roberto Schuster picture Roberto Schuster · Aug 1, 2011 · Viewed 7.2k times · Source

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?

Answer

RoboKozo picture RoboKozo · Aug 3, 2011

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);