DhtmlxTree控件实现右键菜单的方法
来源:互联网 发布:湖南软件职业学院地图 编辑:程序博客网 时间:2024/05/22 10:46
DhtmlxTree控件实现右键菜单的方法
免费版的dhtmlxTree不支持右键菜单dhtmlxMenu,需要在源代码dhtmlxtree.js中添加如下代码:
dhtmlXTreeObject.prototype.enableContextMenu=function(menu){
if(!menu&&!menu.showContextMenu) throw new Error("错误的菜单对象!");
var _tree=this;
//绑定菜单事件处理函数
menu.attachEvent("onBeforeContextMenu",function(){
if(_tree.rclk_id){
return true;
}else{
return false;
}
});
menu.attachEvent("onClick",function(){
_tree.rclk_id=null;
});
//绑定树控件相关时间处理函数
_tree.attachEvent("onClick",function(sId){
if(_tree.lastFocusItem){
if(_isIE)
_tree.lastFocusItem.className="standartTreeRow";
else
_tree.lastFocusItem.setAttribute("class","standartTreeRow");
}
_tree.lastFocusItem=_tree._idpull[sId].span;
});
_tree.attachEvent("onRightClick",function(id,e){
var srcEl=e.target||e.srcElement;
if(srcEl.tagName!="SPAN") return;
if(_tree.lastFocusItem){
if(_isIE)
_tree.lastFocusItem.className="standartTreeRow";
else
_tree.lastFocusItem.setAttribute("class","standartTreeRow");
}
_tree.lastFocusItem=srcEl;
if(_isIE)
srcEl.className="selectedTreeRow";
else
srcEl.setAttribute("class","selectedTreeRow");
_tree.rclk_id=id;
});
}
然后js中通过以下代码就可实现(详细可见dhtmlxMenu提供的Demo):
_menu = new dhtmlXMenuObject(“ROOT”);
_menu.setImagePath(_menuImagePath);
_menu.setIconsPath(_menuIconsPath);
_menu.renderAsContextMenu(true);
_menu.loadXML(“dhtmlxmenu.xml?n="+new Date());
_tree = new dhtmlXTreeObject(“ROOT”, "100%", "100%", _treeId);
_tree.enableContextMenu(_menu);
其中dhtmlxmenu.xml格式为:
<?xml version="1.0"?>
<menu>
<item id="muItem_ADD" text="新建子菜单项" img="new.gif"/>
<item type="separator"/>
<item id="muItem_EDIT" text="编辑菜单项" img="edit.gif"/>
<item type="separator"/>
<item id="muItem_UP" text="上移" img="undo.gif"/>
<item type="separator"/>
<item id="muItem_DOWN" text="下移" img="redo.gif"/>
<item type="separator"/>
<item id="muItem_DELETE" text="删除菜单项" img="del.gif"/>
</menu>
- DhtmlxTree控件实现右键菜单的方法
- 在控件上右键菜单的实现
- 在控件上右键菜单的实现
- TreeList控件右键菜单功能的实现
- CxGrid 的加强右键菜单实现方法
- dhtmlxTree+struts2实现简单的动态树形菜单
- Silverlight系列(右键菜单、控件移动的实现)
- QT右键菜单、右键下拉菜单、各控件响应右键菜单方法简介 【百度空间】
- QT右键菜单、右键下拉菜单、各控件响应右键菜单方法简介 【百度空间】
- QT右键菜单、右键下拉菜单、各控件响应右键菜单方法简介(转)
- 用控件实现自定义右键菜单
- [经验分享]DBGridEH的标题栏,右键菜单实现方法
- dtree+右键菜单 完美结合,超级简单的实现方法
- 添加右键菜单的方法
- MFC 右键菜单的方法
- QListWidget右键菜单的实现
- c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单
- 利用smartmenu实现点击右键出现菜单并实现菜单的只读方法
- 为ProgressDialog 设置button编号
- ISS建站如何远程访问
- IncrediBuild 30天试用过期破解清零工具
- 虚拟机环境搭建
- 《编程之美》1.9:高效率的安排见面会的一个解法
- DhtmlxTree控件实现右键菜单的方法
- 《那些年啊,那些事——一个程序员的奋斗史》——02
- Android 开源项目列表
- 使用JNA调用本地方法
- 使用Generic Trace Support打印调试信息
- 【转】 获取Android SDK 源代码并在Eclipse中关联查看的方法(for sdk2.3)
- winCE与本地电脑之间的文件传递
- EXISTS、IN、NOT EXISTS、NOT IN的区别与性能分析
- android apkbuilder.bat批处理