2

我有一个包含项目的DataGrid。当您右键单击其中一行时,会显示一个Dojo上下文菜单,并带有删除该行的选项。如果您尝试右键单击DataGrid的空白区域,则不会显示上下文菜单....但是,如果您先右键单击一行,然后单击取消菜单选项(不执行任何操作),或者如果您左键单击页面上的其他位置(隐藏上下文菜单),然后右键单击DataGrid的空白区域,显示上下文菜单IS,如果单击上下文菜单中的删除项目选项,它将删除您右键单击的最后一个项目。Dojo DataGrid上下文菜单onRowContextMenu即使在DataGrid的空白区域中右键单击时也会显示

为什么允许它的上下文菜单显示,当你在一个空白区域的DataGrid但只有你已经正确点击DataGrid中的一个项目右击?

任何提示将不胜感激。这里是我的代码到目前为止:

var selectedItem; // This has to be declared "globally" outside of any functions 

function onRowContextMenuFunc(e) { 
    grid5_rowMenu.bindDomNode(e.grid.domNode); 
    selectedItem = e.grid.getItem(e.rowIndex); 
} 

function gridRowContextMenu_onClick(e) { 
    store3.deleteItem(selectedItem); 
} 

<div dojoType="dijit.Menu" id="grid5_rowMenu" jsId="grid5_rowMenu" style="display: none;"> 
    <div dojoType="dijit.MenuItem" onClick="gridRowContextMenu_onClick">Delete</div> 
    <div dojoType="dijit.MenuItem">Cancel</div> 
</div> 

<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutStructure" rowsPerPage="40" onRowContextMenu="onRowContextMenuFunc"></div> 

回答

3

嗯,我不知道是什么原因它允许上下文菜单显示时右击一个空白区域后,才第一次右键点击某个项目,但我没有拿出一个解决办法来解决我的根本问题:右键单击数据网格中的行项目,然后单击以隐藏上下文菜单,然后右键单击数据网格的空白区域并选择菜单项会导致第一次右键单击的rowIndex要通过

这是我的代码;我希望这有助于任何人在未来有同样的问题:

var selectedItem; 

function onRowContextMenu(e) { 
     grid5_rowMenu.bindDomNode(e.grid.domNode); 
     selectedItem = e.grid.getItem(e.rowIndex); 
} 

function gridRowContextMenuExecute(task) { 
     if((task == "remove") && (selectedItem != null)) { 
      store3.deleteItem(selectedItem); 
     } 
     else { 
      selectedItem = null; 
     } 
} 

<div dojoType="dijit.Menu" id="grid5_rowMenu" jsId="grid5_rowMenu" style="display: none;" onBlur="gridRowContextMenuExecute('cancel')"> 
     <div dojoType="dijit.MenuItem" onMouseDown="gridRowContextMenuExecute('remove')">Remove from Transaction</div> 
     <div dojoType="dijit.MenuItem">Cancel</div> 
</div> 

<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutStructure" rowsPerPage="40" onRowContextMenu="onRowContextMenu"></div> 
0

grid5_rowMenu是菜单。

exceptionsrid.domNode是数据网格的DOM节点。

* grid5_rowMenu.bindDomNode(e.grid.domNode); *

它是:给上下文菜单到电网(DOM的节点内的任何地方)。

因为datagrid中的内容总是变化,所以将菜单分配给网格内的元素并不容易。

如果电网不改变它的内容,你可以这样做: * grid5_rowMenu.bindDomNode(e.target.parentElement); *

相关问题