radio.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - Hide With Radio 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. chkStyle: "radio"
  19. },
  20. data: {
  21. key: {
  22. title: "title"
  23. },
  24. simpleData: {
  25. enable: true
  26. }
  27. },
  28. callback: {
  29. onCheck: onCheck
  30. }
  31. };
  32. var zNodes =[
  33. { id:1, pId:0, name:"pNode 1", title:"", checked:true, open:true},
  34. { id:11, pId:1, name:"pNode 11", title:"", checked:true},
  35. { id:111, pId:11, name:"leaf node 111", title:"", checked:true, isHidden:true},
  36. { id:112, pId:11, name:"leaf node 112", title:""},
  37. { id:113, pId:11, name:"leaf node 113", title:""},
  38. { id:12, pId:1, name:"pNode 12", title:"", isHidden:true},
  39. { id:121, pId:12, name:"leaf node 121", title:""},
  40. { id:122, pId:12, name:"leaf node 122", title:"", isHidden:true},
  41. { id:123, pId:12, name:"leaf node 123", title:""},
  42. { id:2, pId:0, name:"pNode 2", title:""},
  43. { id:21, pId:2, name:"pNode 21", title:"", isHidden:true},
  44. { id:211, pId:21, name:"leaf node 211", title:""},
  45. { id:212, pId:21, name:"leaf node 212", title:""},
  46. { id:213, pId:21, name:"leaf node 213", title:""},
  47. { id:22, pId:2, name:"pNode 22", title:""},
  48. { id:221, pId:22, name:"leaf node 221", title:""},
  49. { id:222, pId:22, name:"leaf node 222", title:""},
  50. { id:223, pId:22, name:"leaf node 223", title:""}
  51. ];
  52. function onCheck(e, treeId, treeNode) {
  53. count();
  54. }
  55. function setTitle(node) {
  56. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  57. var nodes = node ? [node]:zTree.transformToArray(zTree.getNodes());
  58. for (var i=0, l=nodes.length; i<l; i++) {
  59. var n = nodes[i];
  60. n.title = "[" + n.id + "] isFirstNode = " + n.isFirstNode + ", isLastNode = " + n.isLastNode;
  61. zTree.updateNode(n);
  62. }
  63. }
  64. function count() {
  65. function isForceHidden(node) {
  66. if (!node.parentTId) return false;
  67. var p = node.getParentNode();
  68. return !!p.isHidden ? true : isForceHidden(p);
  69. }
  70. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  71. checkCount = zTree.getCheckedNodes(true).length,
  72. nocheckCount = zTree.getCheckedNodes(false).length,
  73. hiddenNodes = zTree.getNodesByParam("isHidden", true),
  74. hiddenCount = hiddenNodes.length;
  75. for (var i=0, j=hiddenNodes.length; i<j; i++) {
  76. var n = hiddenNodes[i];
  77. if (isForceHidden(n)) {
  78. hiddenCount -= 1;
  79. } else if (n.isParent) {
  80. hiddenCount += zTree.transformToArray(n.children).length;
  81. }
  82. }
  83. $("#isHiddenCount").text(hiddenNodes.length);
  84. $("#hiddenCount").text(hiddenCount);
  85. $("#checkCount").text(checkCount);
  86. $("#nocheckCount").text(nocheckCount);
  87. }
  88. function showNodes() {
  89. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  90. nodes = zTree.getNodesByParam("isHidden", true);
  91. zTree.showNodes(nodes);
  92. setTitle();
  93. count();
  94. }
  95. function hideNodes() {
  96. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  97. nodes = zTree.getSelectedNodes();
  98. if (nodes.length == 0) {
  99. alert("Please select one node at least.");
  100. return;
  101. }
  102. zTree.hideNodes(nodes);
  103. setTitle();
  104. count();
  105. }
  106. $(document).ready(function(){
  107. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  108. $("#hideNodesBtn").bind("click", {type:"rename"}, hideNodes);
  109. $("#showNodesBtn").bind("click", {type:"icon"}, showNodes);
  110. setTitle();
  111. count();
  112. });
  113. //-->
  114. </SCRIPT>
  115. </HEAD>
  116. <BODY>
  117. <h1>Hide With Radio Mode</h1>
  118. <h6>[ File Path: exhide/radio.html ]</h6>
  119. <div class="content_wrap">
  120. <div class="zTreeDemoBackground left">
  121. <ul id="treeDemo" class="ztree"></ul>
  122. </div>
  123. <div class="right">
  124. <ul class="info">
  125. <li class="title"><h2>1, Explanation of setting</h2>
  126. <ul class="list">
  127. <li>Use the freature which to hide nodes, you don't need to set any attributes.</li>
  128. </ul>
  129. </li>
  130. <li class="title"><h2>2, Explanation of treeNode</h2>
  131. <ul class="list">
  132. <li class="highlight_red">Before you init zTree, set treeNode.isHidden = true, and you can hide the node.</li>
  133. <li><p>Hide or show the nodes:<br/>
  134. Try: [ <a id="hideNodesBtn" href="#" onclick="return false;">Hide the nodes which be selected</a> ]<br/>
  135. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="showNodesBtn" href="#" onclick="return false;">Show all of the nodes which be hidden</a> ]<br/>
  136. <ul id="log" class="log" style="height:125px;">
  137. <li>Total nodes which 'isHidden' attribute is true: <span id="isHiddenCount" class="highlight_red"></span></li>
  138. <li>Total hidden nodes: <span id="hiddenCount" class="highlight_red"></span></li>
  139. <li>Total check nodes: <span id="checkCount" class="highlight_red"></span>
  140. &nbsp;&nbsp;Total uncheck nodes: <span id="nocheckCount" class="highlight_red"></span></li>
  141. <li>After hide nodes, you can see the 'isFirstNode' and 'isLastNode' attributes on the nodes which still be shown.</li>
  142. </ul></p>
  143. </li>
  144. </ul>
  145. </li>
  146. <li class="title"><h2>3、Other explanation</h2>
  147. <ul class="list">
  148. <li>Hide nodes will effect the 'isFirstNode' and 'isLastNode' attributes, but will not effect the 'getPreNode()' and 'getNextNode()' method.</li>
  149. </ul>
  150. </li>
  151. </ul>
  152. </div>
  153. </div>
  154. </BODY>
  155. </HTML>