在控制器中显示上下文菜单

时间:2015-06-10 17:34:49

标签: extjs

我有两个views - 一个用于树面板,一个用于上下文菜单(定义为FilesEditor.view.FilesEditorContextMenu)。我有一个controller,它会监听itemcontextmenu事件。我不知道应该如何创建(在哪里以及在什么阶段?)以及如何展示我的FilesEditorContextMenu。监听器的部分如下所示:

itemcontextmenu:function(view, rec, item, index, event){
    event.stopEvent();
    ... What should I do next? How should I instantiate and show a context menu
}

修改

我调查了这个example的代码,它具有与我想要的功能类似的功能,但问题是 - 我无法找到getContextMenu()的实现 - 这是最重要的问题的条款。

1 个答案:

答案 0 :(得分:1)

这是打开上下文菜单的示例代码(这会给你一些想法):

itemcontextmenu: function(view, record, item, index, e, eOpts) {
        var position = e.getXY(),
            menu = Ext.create('FilesEditor.view.FilesEditorContextMenu', {
            id: 'myMenu',
            items: [{
                text: 'Some Menu Item',
                handler: function() {
                    // do your stuff
                }
            }],
            listeners: {
                mouseleave: function() {
                    // close menu
                    menu.close();// check documentation https://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.menu.Menu-method-close
                }
            }
        });
        e.stopEvent(); // prevent the browser default context menu
        menu.refView = view; // passing the view reference to the menu so that we can get a handle of the grid inside the menu item handler
        menu.showAt(position);
    }