checkbox.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - Hide With Checkbox Mode</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. check: {
  17. enable: true
  18. },
  19. data: {
  20. key: {
  21. title: "title"
  22. },
  23. simpleData: {
  24. enable: true
  25. }
  26. },
  27. callback: {
  28. onCheck: onCheck
  29. }
  30. };
  31. var zNodes =[
  32. { id:1, pId:0, name:"父节点1", title:"", checked:true, open:true},
  33. { id:11, pId:1, name:"父节点11", title:"", checked:true},
  34. { id:111, pId:11, name:"叶子节点111", title:"", checked:true, isHidden:true},
  35. { id:112, pId:11, name:"叶子节点112", title:""},
  36. { id:113, pId:11, name:"叶子节点113", title:""},
  37. { id:12, pId:1, name:"父节点12", title:"", isHidden:true},
  38. { id:121, pId:12, name:"叶子节点121", title:""},
  39. { id:122, pId:12, name:"叶子节点122", title:"", isHidden:true},
  40. { id:123, pId:12, name:"叶子节点123", title:""},
  41. { id:2, pId:0, name:"父节点2", title:""},
  42. { id:21, pId:2, name:"父节点21", title:"", isHidden:true},
  43. { id:211, pId:21, name:"叶子节点211", title:""},
  44. { id:212, pId:21, name:"叶子节点212", title:""},
  45. { id:213, pId:21, name:"叶子节点213", title:""},
  46. { id:22, pId:2, name:"父节点22", title:""},
  47. { id:221, pId:22, name:"叶子节点221", title:""},
  48. { id:222, pId:22, name:"叶子节点222", title:""},
  49. { id:223, pId:22, name:"叶子节点223", title:""}
  50. ];
  51. function onCheck(e, treeId, treeNode) {
  52. count();
  53. }
  54. function setTitle(node) {
  55. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  56. var nodes = node ? [node]:zTree.transformToArray(zTree.getNodes());
  57. for (var i=0, l=nodes.length; i<l; i++) {
  58. var n = nodes[i];
  59. n.title = "[" + n.id + "] isFirstNode = " + n.isFirstNode + ", isLastNode = " + n.isLastNode;
  60. zTree.updateNode(n);
  61. }
  62. }
  63. function count() {
  64. function isForceHidden(node) {
  65. if (!node.parentTId) return false;
  66. var p = node.getParentNode();
  67. return !!p.isHidden ? true : isForceHidden(p);
  68. }
  69. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  70. checkCount = zTree.getCheckedNodes(true).length,
  71. nocheckCount = zTree.getCheckedNodes(false).length,
  72. hiddenNodes = zTree.getNodesByParam("isHidden", true),
  73. hiddenCount = hiddenNodes.length;
  74. for (var i=0, j=hiddenNodes.length; i<j; i++) {
  75. var n = hiddenNodes[i];
  76. if (isForceHidden(n)) {
  77. hiddenCount -= 1;
  78. } else if (n.isParent) {
  79. hiddenCount += zTree.transformToArray(n.children).length;
  80. }
  81. }
  82. $("#isHiddenCount").text(hiddenNodes.length);
  83. $("#hiddenCount").text(hiddenCount);
  84. $("#checkCount").text(checkCount);
  85. $("#nocheckCount").text(nocheckCount);
  86. }
  87. function showNodes() {
  88. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  89. nodes = zTree.getNodesByParam("isHidden", true);
  90. zTree.showNodes(nodes);
  91. setTitle();
  92. count();
  93. }
  94. function hideNodes() {
  95. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  96. nodes = zTree.getSelectedNodes();
  97. if (nodes.length == 0) {
  98. alert("请至少选择一个节点");
  99. return;
  100. }
  101. zTree.hideNodes(nodes);
  102. setTitle();
  103. count();
  104. }
  105. $(document).ready(function(){
  106. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  107. $("#hideNodesBtn").bind("click", {type:"rename"}, hideNodes);
  108. $("#showNodesBtn").bind("click", {type:"icon"}, showNodes);
  109. setTitle();
  110. count();
  111. });
  112. //-->
  113. </SCRIPT>
  114. </HEAD>
  115. <BODY>
  116. <h1>配合 checkbox 的隐藏</h1>
  117. <h6>[ 文件路径: exhide/checkbox.html ]</h6>
  118. <div class="content_wrap">
  119. <div class="zTreeDemoBackground left">
  120. <ul id="treeDemo" class="ztree"></ul>
  121. </div>
  122. <div class="right">
  123. <ul class="info">
  124. <li class="title"><h2>1、setting 配置信息说明</h2>
  125. <ul class="list">
  126. <li>使用隐藏功能,无需设置任何参数</li>
  127. </ul>
  128. </li>
  129. <li class="title"><h2>2、treeNode 节点数据说明</h2>
  130. <ul class="list">
  131. <li class="highlight_red">初始化时,设置 treeNode.isHidden = true; 可以让节点隐藏</li>
  132. <li><p>隐藏、显示节点,看看树的变化:<br/><br/>
  133. 试试看:[ <a id="hideNodesBtn" href="#" onclick="return false;">隐藏选中的节点</a> ]
  134. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="showNodesBtn" href="#" onclick="return false;">显示全部被隐藏的节点</a> ]<br/><br/>
  135. <ul id="log" class="log" style="height:125px;">
  136. <li>isHidden = true 的节点共 <span id="isHiddenCount" class="highlight_red"></span> 个</li>
  137. <li>被隐藏的节点共 <span id="hiddenCount" class="highlight_red"></span> 个</li>
  138. <li>当前被勾选的节点共 <span id="checkCount" class="highlight_red"></span> 个</li>
  139. <li>当前未被勾选的节点共 <span id="nocheckCount" class="highlight_red"></span> 个</li>
  140. <li>隐藏节点后,可以看看仍显示节点的 isFirstNode 和 isLastNode 属性</li>
  141. </ul></p>
  142. </li>
  143. </ul>
  144. </li>
  145. <li class="title"><h2>3、其他说明</h2>
  146. <ul class="list">
  147. <li>隐藏节点操作,会影响 isFirstNode 和 isLastNode 属性,但是对于 getPreNode() 和 getNextNode() 方法无影响</li>
  148. </ul>
  149. </li>
  150. </ul>
  151. </div>
  152. </div>
  153. </BODY>
  154. </HTML>