radio_fun.html 5.2 KB

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