radio_fun.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - beforeCheck / onCheck</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.min.js"></script>
  9. <!-- <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>-->
  10. <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
  12. <!--
  13. <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
  14. -->
  15. <SCRIPT type="text/javascript">
  16. <!--
  17. var setting = {
  18. view: {
  19. selectedMulti: false
  20. },
  21. check: {
  22. enable: true,
  23. chkStyle: "radio",
  24. radioType: "level"
  25. },
  26. data: {
  27. simpleData: {
  28. enable: true
  29. }
  30. },
  31. callback: {
  32. beforeCheck: beforeCheck,
  33. onCheck: onCheck
  34. }
  35. };
  36. var zNodes =[
  37. { id:1, pId:0, name:"can check 1", open:true},
  38. { id:11, pId:1, name:"no radio 1-1", nocheck:true},
  39. { id:12, pId:1, name:"can check 1-2", open:true},
  40. { id:121, pId:12, name:"can check 1-2-1"},
  41. { id:122, pId:12, name:"can check 1-2-2"},
  42. { id:123, pId:12, name:"no radio 1-2-3", nocheck:true},
  43. { id:13, pId:1, name:"can check 1-3"},
  44. { id:2, pId:0, name:"can't check 2", open:true, doCheck:false},
  45. { id:21, pId:2, name:"can't check 2-1", doCheck:false},
  46. { id:22, pId:2, name:"can't check 2-2", checked:true, open:true, doCheck:false},
  47. { id:221, pId:22, name:"can't chk 2-2-1", doCheck:false},
  48. { id:222, pId:22, name:"can't chk 2-2-2", checked:true, doCheck:false},
  49. { id:223, pId:22, name:"can't chk 2-2-3", doCheck:false},
  50. { id:23, pId:2, name:"can't check 2-3", doCheck:false}
  51. ];
  52. var code, log, className = "dark";
  53. function beforeCheck(treeId, treeNode) {
  54. className = (className === "dark" ? "":"dark");
  55. showLog("[ "+getTime()+" beforeCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
  56. return (treeNode.doCheck !== false);
  57. }
  58. function onCheck(e, treeId, treeNode) {
  59. showLog("[ "+getTime()+" onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
  60. }
  61. function showLog(str) {
  62. if (!log) log = $("#log");
  63. log.append("<li class='"+className+"'>"+str+"</li>");
  64. if(log.children("li").length > 6) {
  65. log.get(0).removeChild(log.children("li")[0]);
  66. }
  67. }
  68. function getTime() {
  69. var now= new Date(),
  70. h=now.getHours(),
  71. m=now.getMinutes(),
  72. s=now.getSeconds(),
  73. ms=now.getMilliseconds();
  74. return (h+":"+m+":"+s+ " " +ms);
  75. }
  76. function checkNode(e) {
  77. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  78. type = e.data.type,
  79. nodes = zTree.getSelectedNodes();
  80. if (type.indexOf("All")<0 && nodes.length == 0) {
  81. alert("Please select one node at first...");
  82. }
  83. if (type == "checkAllTrue") {
  84. zTree.checkAllNodes(true);
  85. } else if (type == "checkAllFalse") {
  86. zTree.checkAllNodes(false);
  87. } else {
  88. var callbackFlag = $("#callbackTrigger").attr("checked");
  89. for (var i=0, l=nodes.length; i<l; i++) {
  90. if (type == "checkTrue") {
  91. zTree.checkNode(nodes[i], true, null, callbackFlag);
  92. } else if (type == "checkFalse") {
  93. zTree.checkNode(nodes[i], false, null, callbackFlag);
  94. }else if (type == "checkTruePS") {
  95. zTree.checkNode(nodes[i], true, true, callbackFlag);
  96. } else if (type == "checkFalsePS") {
  97. zTree.checkNode(nodes[i], false, true, callbackFlag);
  98. }
  99. }
  100. }
  101. }
  102. $(document).ready(function(){
  103. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  104. $("#checkTrue").bind("click", {type:"checkTrue"}, checkNode);
  105. $("#checkFalse").bind("click", {type:"checkFalse"}, checkNode);
  106. });
  107. //-->
  108. </SCRIPT>
  109. </HEAD>
  110. <BODY>
  111. <h1>Radio - zTree methods</h1>
  112. <h6>[ File Path: excheck/radio_fun.html ]</h6>
  113. <div class="content_wrap">
  114. <div class="zTreeDemoBackground left">
  115. <ul id="treeDemo" class="ztree"></ul>
  116. </div>
  117. <div class="right">
  118. <ul class="info">
  119. <li class="title"><h2>1, 'beforeCheck / onCheck' callback function</h2>
  120. <ul class="list">
  121. <li>Use 'beforeCheck / onCheck' callback function can control whether to allow changes to the node check state. This simple demo shows how to monitor the check event.</li>
  122. <li><p>By the way also demonstrates how to use the 'checkNode' method triggers 'beforeCheck / onCheck' callback, Try: <br/>
  123. &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="callbackTrigger" checked /> Whether trigger the callback when execution checkNode() method.<br/>
  124. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="checkTrue" href="#" title="check..." onclick="return false;">check</a> ]
  125. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="checkFalse" href="#" title="uncheck..." onclick="return false;">uncheck</a> ]</p>
  126. <li><p><span class="highlight_red">How to use 'zTreeObj.checkNode' method, please see the API documentation.</span><br/>
  127. beforeCheck / onCheck log:<br/>
  128. <ul id="log" class="log" style="height:130px;"></ul></p>
  129. </li>
  130. </ul>
  131. </li>
  132. <li class="title"><h2>2, Explanation of setting</h2>
  133. <ul class="list">
  134. <li>Same as 'Radio Operation'</li>
  135. </ul>
  136. </li>
  137. <li class="title"><h2>3, Explanation of treeNode</h2>
  138. <ul class="list">
  139. <li>Same as 'Radio Operation'</li>
  140. </ul>
  141. </li>
  142. </ul>
  143. </div>
  144. </div>
  145. </BODY>
  146. </HTML>