left_menu.html 5.4 KB

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