common.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - Hide Ordinary Node</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <!--<script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>-->
  12. <script type="text/javascript" src="../../../js/jquery.ztree.exhide-3.5.js"></script>
  13. <SCRIPT type="text/javascript">
  14. <!--
  15. var setting = {
  16. data: {
  17. key: {
  18. title: "title"
  19. },
  20. simpleData: {
  21. enable: true
  22. }
  23. }
  24. };
  25. var zNodes =[
  26. { id:1, pId:0, name:"父节点1", title:"", open:true},
  27. { id:11, pId:1, name:"父节点11", title:""},
  28. { id:111, pId:11, name:"叶子节点111", title:"", isHidden:true},
  29. { id:112, pId:11, name:"叶子节点112", title:""},
  30. { id:113, pId:11, name:"叶子节点113", title:""},
  31. { id:12, pId:1, name:"父节点12", title:"", isHidden:true},
  32. { id:121, pId:12, name:"叶子节点121", title:""},
  33. { id:122, pId:12, name:"叶子节点122", title:"", isHidden:true},
  34. { id:123, pId:12, name:"叶子节点123", title:""},
  35. { id:2, pId:0, name:"父节点2", title:""},
  36. { id:21, pId:2, name:"父节点21", title:"", isHidden:true},
  37. { id:211, pId:21, name:"叶子节点211", title:""},
  38. { id:212, pId:21, name:"叶子节点212", title:""},
  39. { id:213, pId:21, name:"叶子节点213", title:""},
  40. { id:22, pId:2, name:"父节点22", title:""},
  41. { id:221, pId:22, name:"叶子节点221", title:""},
  42. { id:222, pId:22, name:"叶子节点222", title:""},
  43. { id:223, pId:22, name:"叶子节点223", title:""}
  44. ];
  45. function setTitle(node) {
  46. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  47. var nodes = node ? [node]:zTree.transformToArray(zTree.getNodes());
  48. for (var i=0, l=nodes.length; i<l; i++) {
  49. var n = nodes[i];
  50. n.title = "[" + n.id + "] isFirstNode = " + n.isFirstNode + ", isLastNode = " + n.isLastNode;
  51. zTree.updateNode(n);
  52. }
  53. }
  54. function count() {
  55. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  56. hiddenCount = zTree.getNodesByParam("isHidden", true).length;
  57. $("#hiddenCount").text(hiddenCount);
  58. }
  59. function showNodes() {
  60. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  61. nodes = zTree.getNodesByParam("isHidden", true);
  62. zTree.showNodes(nodes);
  63. setTitle();
  64. count();
  65. }
  66. function hideNodes() {
  67. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  68. nodes = zTree.getSelectedNodes();
  69. if (nodes.length == 0) {
  70. alert("请至少选择一个节点");
  71. return;
  72. }
  73. zTree.hideNodes(nodes);
  74. setTitle();
  75. count();
  76. }
  77. $(document).ready(function(){
  78. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  79. $("#hideNodesBtn").bind("click", {type:"rename"}, hideNodes);
  80. $("#showNodesBtn").bind("click", {type:"icon"}, showNodes);
  81. setTitle();
  82. count();
  83. });
  84. //-->
  85. </SCRIPT>
  86. </HEAD>
  87. <BODY>
  88. <h1>隐藏普通节点</h1>
  89. <h6>[ 文件路径: exhide/common.html ]</h6>
  90. <div class="content_wrap">
  91. <div class="zTreeDemoBackground left">
  92. <ul id="treeDemo" class="ztree"></ul>
  93. </div>
  94. <div class="right">
  95. <ul class="info">
  96. <li class="title"><h2>1、setting 配置信息说明</h2>
  97. <ul class="list">
  98. <li>使用此功能,无需设置任何参数</li>
  99. </ul>
  100. </li>
  101. <li class="title"><h2>2、treeNode 节点数据说明</h2>
  102. <ul class="list">
  103. <li class="highlight_red">初始化时,设置 treeNode.isHidden = true; 可以让节点隐藏</li>
  104. <li><p>隐藏、显示节点,看看树的变化:<br/><br/>
  105. 试试看:[ <a id="hideNodesBtn" href="#" onclick="return false;">隐藏选中的节点</a> ]
  106. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="showNodesBtn" href="#" onclick="return false;">显示全部被隐藏的节点</a> ]<br/><br/>
  107. <ul id="log" class="log" style="height:65px;">
  108. <li>isHidden = true 的节点共 <span id="hiddenCount" class="highlight_red"></span> 个</li>
  109. <li>隐藏节点后,可以看看仍显示节点的 isFirstNode 和 isLastNode 属性</li>
  110. </ul></p>
  111. </li>
  112. </ul>
  113. </li>
  114. <li class="title"><h2>3、其他说明</h2>
  115. <ul class="list">
  116. <li>隐藏节点操作,会影响 isFirstNode 和 isLastNode 属性,但是对于 getPreNode() 和 getNextNode() 方法无影响</li>
  117. </ul>
  118. </li>
  119. </ul>
  120. </div>
  121. </div>
  122. </BODY>
  123. </HTML>