left_menu.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - left_menu</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. <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>-->
  13. <SCRIPT type="text/javascript">
  14. <!--
  15. var curMenu = null, zTree_Menu = null;
  16. var setting = {
  17. view: {
  18. showLine: true,
  19. selectedMulti: false,
  20. dblClickExpand: false
  21. },
  22. data: {
  23. simpleData: {
  24. enable: true
  25. }
  26. },
  27. callback: {
  28. onNodeCreated: this.onNodeCreated,
  29. beforeClick: this.beforeClick,
  30. onClick: this.onClick
  31. }
  32. };
  33. var zNodes =[
  34. { id:1, pId:0, name:"Main Menu 1", open:true},
  35. { id:11, pId:1, name:"Sub Menu 1-1"},
  36. { id:111, pId:11, name:"Leaf Node 1-1-1"},
  37. { id:112, pId:11, name:"Leaf Node 1-1-2"},
  38. { id:113, pId:11, name:"Leaf Node 1-1-3"},
  39. { id:114, pId:11, name:"Leaf Node 1-1-4"},
  40. { id:12, pId:1, name:"Sub Menu 1-2"},
  41. { id:121, pId:12, name:"Leaf Node 1-2-1"},
  42. { id:122, pId:12, name:"Leaf Node 1-2-2"},
  43. { id:123, pId:12, name:"Leaf Node 1-2-3"},
  44. { id:124, pId:12, name:"Leaf Node 1-2-4"},
  45. { id:2, pId:0, name:"Main Menu 2"},
  46. { id:21, pId:2, name:"Sub Menu 2-1"},
  47. { id:211, pId:21, name:"Leaf Node 2-1-1"},
  48. { id:212, pId:21, name:"Leaf Node 2-1-2"},
  49. { id:213, pId:21, name:"Leaf Node 2-1-3"},
  50. { id:214, pId:21, name:"Leaf Node 2-1-4"},
  51. { id:22, pId:2, name:"Sub Menu 2-2"},
  52. { id:221, pId:22, name:"Leaf Node 2-2-1"},
  53. { id:222, pId:22, name:"Leaf Node 2-2-2"},
  54. { id:223, pId:22, name:"Leaf Node 2-2-3"},
  55. { id:224, pId:22, name:"Leaf Node 2-2-4"},
  56. { id:3, pId:0, name:"Main Menu 3"},
  57. { id:31, pId:3, name:"Sub Menu 3-1"},
  58. { id:311, pId:31, name:"Leaf Node 3-1-1"},
  59. { id:312, pId:31, name:"Leaf Node 3-1-2"},
  60. { id:313, pId:31, name:"Leaf Node 3-1-3"},
  61. { id:314, pId:31, name:"Leaf Node 3-1-4"},
  62. { id:32, pId:3, name:"Sub Menu 3-2"},
  63. { id:321, pId:32, name:"Leaf Node 3-2-1"},
  64. { id:322, pId:32, name:"Leaf Node 3-2-2"},
  65. { id:323, pId:32, name:"Leaf Node 3-2-3"},
  66. { id:324, pId:32, name:"Leaf Node 3-2-4"}
  67. ];
  68. function beforeClick(treeId, node) {
  69. if (node.isParent) {
  70. if (node.level === 0) {
  71. var pNode = curMenu;
  72. while (pNode && pNode.level !==0) {
  73. pNode = pNode.getParentNode();
  74. }
  75. if (pNode !== node) {
  76. var a = $("#" + pNode.tId + "_a");
  77. a.removeClass("cur");
  78. zTree_Menu.expandNode(pNode, false);
  79. }
  80. a = $("#" + node.tId + "_a");
  81. a.addClass("cur");
  82. var isOpen = false;
  83. for (var i=0,l=node.children.length; i<l; i++) {
  84. if(node.children[i].open) {
  85. isOpen = true;
  86. break;
  87. }
  88. }
  89. if (isOpen) {
  90. zTree_Menu.expandNode(node, true);
  91. curMenu = node;
  92. } else {
  93. zTree_Menu.expandNode(node.children[0].isParent?node.children[0]:node, true);
  94. curMenu = node.children[0];
  95. }
  96. } else {
  97. zTree_Menu.expandNode(node);
  98. }
  99. }
  100. return !node.isParent;
  101. }
  102. function onClick(e, treeId, node) {
  103. alert("Do what you want to do!");
  104. }
  105. $(document).ready(function(){
  106. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  107. zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo");
  108. curMenu = zTree_Menu.getNodes()[0].children[0].children[0];
  109. zTree_Menu.selectNode(curMenu);
  110. var a = $("#" + zTree_Menu.getNodes()[0].tId + "_a");
  111. a.addClass("cur");
  112. });
  113. //-->
  114. </SCRIPT>
  115. <style type="text/css">
  116. .ztree li a.level0 {width:200px;height: 20px; text-align: center; display:block; background-color: #0B61A4; border:1px silver solid;}
  117. .ztree li a.level0.cur {background-color: #66A3D2; }
  118. .ztree li a.level0 span {display: block; color: white; padding-top:3px; font-size:12px; font-weight: bold;word-spacing: 2px;}
  119. .ztree li a.level0 span.button { float:right; margin-left: 10px; visibility: visible;display:none;}
  120. .ztree li span.button.switch.level0 {display:none;}
  121. </style>
  122. </HEAD>
  123. <BODY>
  124. <h1>Left Menu</h1>
  125. <h6>[ File Path: super/left_menu.html ]</h6>
  126. <div class="content_wrap">
  127. <div class="zTreeDemoBackground left">
  128. <ul id="treeDemo" class="ztree"></ul>
  129. </div>
  130. <div class="right">
  131. <ul class="info">
  132. <li class="title"><h2>Explanation of implementation method</h2>
  133. <ul class="list">
  134. <li>The menu in the Demo's Web page is to use zTree to achieve, is to use css set interface, use the configuration 'setting' to achieve features, this demo achieve a simple example of the left menu, you can view the source code of Demo's Web Page for in-depth study.</li>
  135. <li class="highlight_red">1. According to your needs to modify the css, for example: the menu style on this Demo and Demo's Web page not the same.</li>
  136. <li class="highlight_red">2. Main configuration:<br/>
  137. &nbsp;&nbsp;&nbsp;&nbsp;setting.view.showIcon / showLine / selectedMulti / dblClickExpand<br/>
  138. &nbsp;&nbsp;&nbsp;&nbsp;setting.callback.onNodeCreated / beforeClick / onClick
  139. </li>
  140. <li>3. If need to keep single path, please refer to the source code of "Keep Single Path" Demo.</li>
  141. <li>4. Other auxiliary rules, please write code based on your needs.</li>
  142. </ul>
  143. </li>
  144. </ul>
  145. </div>
  146. </div>
  147. </BODY>
  148. </HTML>