首页 > 解决方案 > extjs6 - 网格上下文菜单,通过行选择

问题描述

在我的 extjs6 项目中,我有一个网格,我想添加功能以右键单击网格,从菜单栏中选择项目并启动弹出窗口,但将行选择传递给单击方法。

到目前为止,我的右键菜单栏正在工作,但是当单击菜单项时,我想通过网格中的选定行。有人可以帮我将网格行选择传递给控制器​​方法吗?

我的观点

Ext.define('Example.ContextMenu', {
xtype: 'contextMenuMarketDrilldownAccount',
extend: 'Ext.menu.Menu',
items: [{
    text: 'Market Drilldown by Account',
    listeners: {
        click: 'onDownloadTopdayRecapContextButton2'
    }
}]
});

             //removing a lot of code to make it readable here
            xtype: 'grid',
            title: 'Details',
            itemId: 'detailsGridID',
            bind: {
                store: '{myDetailsStore}'
            },
            flex: 3,
            margin: '5px 0px 0px 0px',
            ui: 'featuredpanel-framed',
            cls: 'custom-grid',
            height: '100%',
            collapsible: true,
            collapseDirection: 'left',
            listeners: {
                itemcontextmenu: 'showContextMenu2'
            },

控制器

    showContextMenu2: function (view, rec, node, index, e) {
    e.stopEvent();
    debugger;
    //var selectedMarket = rec.get('BBSymbol');
    this.getContextMenu2().show().setPagePosition(e.getXY());
    return false;
},

getContextMenu2: function () {
    if (!this.contextMenu) {
        this.contextMenu = this.getView().add({ xtype: 'contextMenuMarketDrilldownAccount' });
    }
    return this.contextMenu;
},

标签: extjscontextmenu

解决方案


要解决问题,请将块this.getContextMenu2()更改为this.getContextMenu2(rec)

showContextMenu2: function (view, rec, node, index, e) {
    e.stopEvent();
    debugger;
    //var selectedMarket = rec.get('BBSymbol');
    this.getContextMenu2(rec).show().setPagePosition(e.getXY());
    return false;
},

getContextMenu2: function (rec) {
    if (!this.contextMenu) {
        this.contextMenu = this.getView().add({ 
            xtype: 'contextMenuMarketDrilldownAccount',
            currentRecord: rec 
        });
    }
    return this.contextMenu;
}

//Then you catch a currentRecord on a contextMenuMarketDrilldownAccount component.

推荐阅读