在Extjs4中鼠标的右键相应事件为
itemcontextmenu( Ext.view.View this, Ext.data.Model record,
HTMLElement item, Number index, Ext.EventObject e, Object eOpts )
使用时直接在listeners中添加即可:
- listeners:{
- 'itemcontextmenu':function(view,record,item,index,e,eOpts){
- //禁用浏览器的右键相应事件
- e.preventDefault();
- e.stopEvent();
-
- var menu = new Ext.menu.Menu({
- //控制右键菜单位置
- float:true,
- items:[{
- text:"修改",
- iconCls:'leaf',
- handler:function(){
- //当点击时隐藏右键菜单
- this.up("menu").hide();
- alert(record.raw.name);
- }
- },{
- text:"添加",
- iconCls:'leaf',
- handler:function(){
- this.up("menu").hide();
- alert("添加");
- }
- },{
- text:"删除",
- iconCls:'leaf',
- handler:function(){
- this.up("menu").hide();
- alert("删除");
- }
- }
- ]
- }).showAt(e.getXY());//让右键菜单跟随鼠标位置
- }
- }
|