2
我在ExtJS網格中使用contextmenu。這是正確的。我的問題是當我使用右鍵單擊然後菜單出現。同樣,當我更改網格行時,上下文菜單不會消失。ContextMenu不會從ExtJs Grid中消失
我的代碼
Ext.application({
name: 'Fiddle',
launch: function() {
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
width: 400,
height: 500,
title: 'itemcontextmenu',
store: {
fields: ['name', 'email', 'phone'],
data: [
{
'name': 'Lisa',
"email": "[email protected]",
"phone": "555-111-1224"
},
{
'name': 'Bart',
"email": "[email protected]",
"phone": "555-222-1234"
},
{
'name': 'Homer',
"email": "[email protected]",
"phone": "555-222-1244"
},
{
'name': 'Marge',
"email": "[email protected]",
"phone": ""
}
]
},
columns: [
{
text: 'Name',
dataIndex: 'name',
flex: 1
}
],
listeners:[
{
rowclick: function(a , record , element , rowIndex , e , eOpts) {
debugger;
if (rowIndex == 1)
{
alert("Hello");
}
else if (rowIndex == 2)
{
alert("Maddy");
}
}
}
]
});
var contextMenu = Ext.create('Ext.menu.Menu', {
width: 200,
items: [
{
text: 'Preview',
handler: function() {
var record = grid ? grid.getSelection()[0] : null;
if (!record)
{
return;
}
alert(record.get('name'));
}
}
]
});
grid.on("itemcontextmenu", function(grid, record, item, index, e) {
e.stopEvent();
contextMenu.showAt(e.getXY());
});
}
});
可有人請向我解釋,爲什麼發生這種情況?我的工作小提琴here
重現步驟:
- 右鍵點擊一個行,你預覽菜單
- 現在點擊兩排。理想情況下,預覽應該消失,但不會發生。
感謝您的回答 – David