关于zTree.addNodes(parentNode, newNode) 树无反应
@zTree 你好,想跟你请教个问题:
做zTree 增删改基本功能demo时,用zTree.addNodes 方法 添加节点,树没有反应。
仔细检查了各个地方仍然无法解决,请赐教。
<!DOCTYPE html> <HTML> <HEAD> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../js/ztree/css/zTreeStyle.css" type="text/css"> <script type="text/javascript" src="../js/ztree/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="../js/ztree/js/jquery.ztree.core-3.3.js"></script> <script type="text/javascript" src="../js/ztree/js/jquery.ztree.excheck-3.3.js"></script> <script type="text/javascript" src="../js/ztree/js/jquery.ztree.exedit-3.3.js"></script> <SCRIPT type="text/javascript"> <!-- $(document).ready(function() { var zTreeObj; var zNodeTemp; var houseIcon = "../js/ztree/css/img/diy/1_open.png"; var roleIcon = "../js/ztree/css/img/diy/role.png"; var mainMenu = "../js/ztree/css/img/diy/main.png"; var setting = { view: { selectedMulti: false }, edit: { enable: true, showRemoveBtn: false, showRenameBtn: false }, check: { enable: true, chkStyle: "radio", radioType: "all" }, data: { keep: { parent:true, leaf:true }, simpleData: { enable: true } }, callback: { onCheck: onCheck } }; function NodeRadio(id, pId, name, isParent,open,icon,nocheck){ this.id = id; this.pId = pId; this.name = name; this.isParent = isParent; this.open = open; this.icon = icon; this.nocheck = nocheck; }; function onCheck(event, treeId, treeNode, clickFlag) {} //初始化角色 loadRole(); function loadRole(){ var zNodes = new Array; $.ajax( { type : 'Get', url : '../**/getroles', cache:false, dataType : 'json', global : false, async : false, success : function(list) { *** }, error : function() { alert("***"); } }); zTreeObj = $.fn.zTree.init($("#treeRole"), setting, zNodes); } //添加 $("#add").bind("click", {isParent:false}, addNode); function addNode(e){ var zTree = $.fn.zTree.getZTreeObj("treeRole"); var parentNode = zNodeTemp[0]; var newNodeId = parseInt(zNodeTemp[zNodeTemp.length-1].id)+1; var newNode = new NodeRadio("12", "0", "角色名称", false,true,roleIcon,false); treeNode = zTree.addNodes(parentNode, newNode); if (treeNode) { zTree.editName(treeNode[0]); } else { alert("叶子节点被锁定,无法增加子节点"); } zNodeTemp.push(newNode); } //end }); //--> </SCRIPT> <style> <-- --> </style> </HEAD> <body> <ul id="treeRole" class="ztree"></ul> </body> </HTML>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
非常感谢
新增的节点newNode 是没问题的啊
请检查你的
newNode 是否正常?