checkbox_halfCheck.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - Checkbox halfCheck</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. async: {
  18. enable: true,
  19. url:"../asyncData/getNodes.php",
  20. autoParam:["id", "name=n", "level=lv"],
  21. otherParam:{"chk":"chk"},
  22. dataFilter: dataFilter
  23. },
  24. check: {
  25. enable: true,
  26. autoCheckTrigger: true
  27. },
  28. data: {
  29. simpleData: {
  30. enable: true
  31. }
  32. },
  33. callback: {
  34. onCheck: onCheck,
  35. onAsyncSuccess: onAsyncSuccess
  36. }
  37. };
  38. function dataFilter(treeId, parentNode, childNodes) {
  39. if (parentNode.checkedEx === true) {
  40. for(var i=0, l=childNodes.length; i<l; i++) {
  41. childNodes[i].checked = parentNode.checked;
  42. childNodes[i].halfCheck = false;
  43. childNodes[i].checkedEx = true;
  44. }
  45. }
  46. return childNodes;
  47. }
  48. function onCheck(event, treeId, treeNode) {
  49. cancelHalf(treeNode)
  50. treeNode.checkedEx = true;
  51. }
  52. function onAsyncSuccess(event, treeId, treeNode, msg) {
  53. cancelHalf(treeNode);
  54. }
  55. function cancelHalf(treeNode) {
  56. if (treeNode.checkedEx) return;
  57. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  58. treeNode.halfCheck = false;
  59. zTree.updateNode(treeNode);
  60. }
  61. var zNodes =[
  62. { id:1, pId:0, name:"半勾选 1", halfCheck:true, isParent:true},
  63. { id:2, pId:0, name:"半勾选 2", halfCheck:true, checked:true, isParent:true},
  64. { id:3, pId:0, name:"随意勾选 3", checked:true, isParent:true}
  65. ];
  66. $(document).ready(function(){
  67. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  68. });
  69. //-->
  70. </SCRIPT>
  71. </HEAD>
  72. <BODY>
  73. <h1>Checkbox halfCheck 演示</h1>
  74. <h6>[ 文件路径: excheck/checkbox_halfCheck.html ]</h6>
  75. <div class="content_wrap">
  76. <div class="zTreeDemoBackground left">
  77. <ul id="treeDemo" class="ztree"></ul>
  78. </div>
  79. <div class="right">
  80. <ul class="info">
  81. <li class="title"><h2>1、演示说明</h2>
  82. <ul class="list">
  83. <li>这个演示式实现了 异步加载模式 下简单的勾选操作</li>
  84. <li class="highlight_red">1)、加载子节点后,父节点的 halfCheck 立刻失效</li>
  85. <li class="highlight_red">2)、勾选父节点,可以影响之后加载的子节点的勾选状态</li>
  86. <li class="highlight_red">3)、勾选父节点,可以让其子节点的 halfCheck 属性失效</li>
  87. </ul>
  88. </li>
  89. <li class="title"><h2>2、setting 配置信息说明</h2>
  90. <ul class="list">
  91. <li>实现半勾选功能,不需要配置任何参数。但半勾选功能属于辅助功能,无法单独使用,因此也需要根据自己的需求配置特定参数。</li>
  92. </ul>
  93. </li>
  94. <li class="title"><h2>3、treeNode 节点数据说明</h2>
  95. <ul class="list">
  96. <li class="highlight_red">1)、请在节点初始化之前,设置 treeNode.halfCheck 属性,详细请参见 API 文档中的相关内容</li>
  97. <li>2)、其他请参考 ‘Checkbox 勾选操作’</li>
  98. </ul>
  99. </li>
  100. </ul>
  101. </div>
  102. </div>
  103. </BODY>
  104. </HTML>