Question

I have a menu which is defined like that:

Ext.define('MyApp.FileBrowserContextMenu', {
    extend: 'Ext.menu.Menu',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'menuitem',
                    text: 'Edit',
                    listeners: {
                        click: {
                            fn: me.onMenuitemClick,
                            scope: me
                        }
                    }
                },
            ]
        });

        me.callParent(arguments);
    },

    onMenuitemClick: function(item, e, options) {
        var server = this.record;
        var win = Ext.create('widget.ServerWindow', {
            record: server
        });
        win.show();
    }

});

I would like to add new items after the definition, so I try like that:

First I defined the new MenuItem:

Ext.define('MyApp.GitMenuItem', {
    extend: 'Ext.menu.Item',
    alias: 'widget.gitmenuitem',

    text: 'Git',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            menu: {
                xtype: 'menu',
                items: [
                    {
                        xtype: 'menuitem',
                        text: 'Commit',
                        listeners: {
                            click: {
                                fn: me.onMenuitemClick,
                                scope: me
                            }
                        }
                    },
                ]
            }
        });

        me.callParent(arguments);
    },

    onMenuitemClick: function(item, e, options) {

    },

});

Then I try to attach the new menu item:

Ext.override(MyApp.FileBrowserContextMenu, {
    initComponent: function () {
        var me = this;
        this.callParent();
        me.items.items.push(Ext.create('widget.gitmenuitem'));
    }
});

It seems to work, because the new MenuItem appears, but when I go over, Then new Item should appears but I get this error:

Uncaught TypeError: Cannot set property 'activeChild' of undefined

Any ideads ?

Was it helpful?

Solution

The usual way is the add method: menu.add(menuItem).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top