var menu1 = new Ext.menu.Menu({
items: [{
text: 'Open in new tab'
}]
});
var treePanel = Ext.create('Ext.tree.Panel', {
id: 'tree-panel',
region: 'center',
useArrows: true,
singleExpand: true,
split: false,
height: 360,
minSize: 150,
rootVisible: false,
autoScroll: true,
store: store,
border: false,
columns: [{
xtype: 'treecolumn',
dataIndex: 'text',
flex: 2,
sortable: true,
displayField: true
}]
});
treePanel.on('contextmenu', function(event, node) {
alert(node)
//treePanelCurrentNode = node;
x = event.browserEvent.clientX;
y = event.browserEvent.clientY;
menu1.showAt([x, y]);
}, this);
使用4.1 ext js并尝试将上下文菜单添加到此树面板但菜单不起作用。在树面板商店即将到来 但我的代码
treePanel.on('contextmenu', function(event,node){};
无效 不是事件
treePanel.on('click', function(event,node){};
任何与树面板上的ext js上下文菜单相关的想法?
答案 0 :(得分:20)
树在ExtJS4中没有contextmenu
事件。
您应该使用itemcontextmenu
代替contextmenu
:
treePanel.on('itemcontextmenu', function(view, record, item, index, event) {
alert(record)
//treePanelCurrentNode = record;
menu1.showAt(event.getXY());
event.stopEvent();
}, this);
答案 1 :(得分:1)
当呈现数据视图时,它禁用默认的右键单击Web浏览器菜单,这在侦听器“render”事件中调用,“itemcontexmenu”事件用于检测右键单击鼠标事件,捕获鼠标光标位置并显示菜单
listeners: {
render: function() {
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
},
itemcontextmenu : function( grid, record, item, index, event){
x = event.browserEvent.clientX;
y = event.browserEvent.clientY;
menu1.showAt([x, y]);
}
}