微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用dtree生成的树结构,ajax动态加载子节点后,如何绑定右键菜单续

var l_tree = document.getElementById("l_tree_d"); var tree = new dTree("tree");//创建一个对象. tree.add(0,-1,'APISite',"javaScript:getMoreNodes('../treeNodes/NodesPrint','0');"+1+";"+0,'click me!') // 动态显示节点 function getMoreNodes(addr,pId){ $.ajax({ url:addr,type:"POST",//数据发送方式 data:{"parentId":pId},dataType:"xml",//接受数据格式 error:function(json){ alert( "not lived!"); },async: false,//同步方式 success: function(xml){ $(xml).find("node").each(function(){ var nodeId=$(this).attr("nodeId"); var parentId=$(this).attr("parentId"); var nodeType=$(this).attr("nodeType"); var address=$(this).attr("address"); var nodeName=$(this).text(); var child = null; if(nodeType == "0" ){ child = new Node(nodeId,parentId,nodeName,"javaScript:getMoreNodes('"+address+"','"+nodeId+"');"+nodeId+";"+nodeType,nodeName); child._hc = true; }else if(nodeType == "1"){ child = new Node(nodeId,"javaScript:getService('"+address+"');"+nodeId+";"+nodeType,"contentFrame"); }else if(nodeType == "2"){ child = new Node(nodeId,"javaScript:toPage('"+address+"');"+nodeId+";"+nodeType,"contentFrame"); } tree.aNodes[tree.aNodes.length] = child; }); } }); l_tree.innerHTML = tree; $('a[id]',l_tree).contextMenu('myMenu',{ bindings: { 'add': function(t) { var nId = t.toString().split(";")[1]; var nType = t.toString().split(";")[2]; if(nType == "0"){ window.open("addNodes.jsp?nodeId="+nId,"","width=300,height=150,scrollbars=no,top=250,left=500,location=no"); }else{ alert("请选择父节点添加!"); } },'update': function(t) { var nId = t.toString().split(";")[1]; var nType = t.toString().split(";")[2]; window.open("updateNodes.jsp?parentId="+pId+"&nodeId="+nId+"&nodeType="+nType,"width=200,height=100,location=no"); },'delete': function(t) { var nId = t.toString().split(";")[1]; var nType = t.toString().split(";")[2]; if(nType == "0"){ alert("此节点不能删除!"); }else{ if(confirm("确定删除?")){ location.href="/LHApi/treeNodes/DeleteNodes?nodeId="+nId; } } } } }); } document.write(tree); function getService(addr){ self.parent.frames['contentFrame'].location="/LHApi/treeNodes/MethodInfo?address="+addr; } function toPage(addr){ self.parent.frames['contentFrame'].location=addr; } 注:主页面需要导入js包<script type="text/javascript" src="../dtree/jquery.contextmenu.js"></script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐