开发者

In Extjs4 how can I reconfigure an existing menu object?

开发者 https://www.devze.com 2023-04-03 16:53 出处:网络
In extjs4 how can I set the menus in a call later (from), not in the initComponent function? In other words: How can I reconfigure an existing menu object (menu items)?

In extjs4 how can I set the menus in a call later (from), not in the initComponent function?

In other words: How can I reconfigure an existing menu object (menu items)?

Ext.define('My.view.dashboard.CategoryMenu', {
extend: 'Ext.menu.Menu',
alias: 'widget.categorymenu',
id: 'kategoriaMenu',

initComponent: function() {                
    this.callParent(arguments);
},

fetchMenu: function(categoryId) {
    var me=this;

    Ext.Ajax.request(
               {
                url: '/resources/categoryMenu.json',
                method: 'POST',
                params:
                {
                 id: categoryId
                },
                success: function(result, request)
                {
                 var jsonData = Ext.decode(result.responseText);
                 categoryItems=jsonData.items;
                 Ext.apply(me.items, categoryItems);                     
                }
               });
    }

});

This is the original code what is a working code with initComponent initialization:

initComponent: function() {             

                Ext.apply(this, {
        items:
        [
            {
                text: 'Recently Added (last 7 Days)',
                itemId: 'recentlyAdded'
            },
             {
                text: 'Open  Worklist',
                iconCls: 'worklist-icon',
                itemId: 'openWorklist'
            },{
       开发者_JAVA百科         text: 'Open Create Screen',
                iconCls: 'open-create-screen-icon',
                itemId: 'openCreateScreen'
            }
        ]
    });

    this.callParent(arguments);
},

This is how I call it:

        ...
        var ctxMenu = this.getCategoryMenu();
        ctxMenu.fetchMenu(record.data.id);  // get current menu content         
        ctxMenu.setPosition(event.getXY());
        ctxMenu.show();
        ...


Not sure about Ext4, but it should be the same concept as 3. For my app, I had to set the menu items dynamically based on a grid item that they were right clicking on (this was for a ContextMenu, but it should be the same)

ctxMenu.items.items[0]
// items.items because you're nested inside a menu

Will retrieve the first menu item, and from there you can get the others easily (1, 2, 3). Once you have that you can use setText(). You should have access to all of the Ext.menu.Item methods from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消