common.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - big data common</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 setting = {
  15. check: {
  16. enable: true
  17. },
  18. data: {
  19. simpleData: {
  20. enable: true
  21. }
  22. },
  23. callback: {
  24. onNodeCreated: onNodeCreated
  25. }
  26. };
  27. var dataMaker = function(count) {
  28. var nodes = [], pId = -1,
  29. min = 10, max = 90, level = 0, curLevel = [], prevLevel = [], levelCount,
  30. i = 0,j,k,l,m;
  31. while (i<count) {
  32. if (level == 0) {
  33. pId = -1;
  34. levelCount = Math.round(Math.random() * max) + min;
  35. for (j=0; j<levelCount && i<count; j++, i++) {
  36. var n = {id:i, pId:pId, name:"Big-" +i};
  37. nodes.push(n);
  38. curLevel.push(n);
  39. }
  40. } else {
  41. for (l=0, m=prevLevel.length; l<m && i<count; l++) {
  42. pId = prevLevel[l].id;
  43. levelCount = Math.round(Math.random() * max) + min;
  44. for (j=0; j<levelCount && i<count; j++, i++) {
  45. var n = {id:i, pId:pId, name:"Big-" +i};
  46. nodes.push(n);
  47. curLevel.push(n);
  48. }
  49. }
  50. }
  51. prevLevel = curLevel;
  52. curLevel = [];
  53. level++;
  54. }
  55. return nodes;
  56. }
  57. var ruler = {
  58. doc: null,
  59. ruler: null,
  60. cursor: null,
  61. minCount: 5000,
  62. count: 5000,
  63. stepCount:500,
  64. minWidth: 30,
  65. maxWidth: 215,
  66. init: function() {
  67. ruler.doc = $(document);
  68. ruler.ruler = $("#ruler");
  69. ruler.cursor = $("#cursor");
  70. if (ruler.ruler) {
  71. ruler.ruler.bind("mousedown", ruler.onMouseDown);
  72. }
  73. },
  74. onMouseDown: function(e) {
  75. ruler.drawRuler(e, true);
  76. ruler.doc.bind("mousemove", ruler.onMouseMove);
  77. ruler.doc.bind("mouseup", ruler.onMouseUp);
  78. ruler.doc.bind("selectstart", ruler.onSelect);
  79. $("body").css("cursor", "pointer");
  80. },
  81. onMouseMove: function(e) {
  82. ruler.drawRuler(e);
  83. return false;
  84. },
  85. onMouseUp: function(e) {
  86. $("body").css("cursor", "auto");
  87. ruler.doc.unbind("mousemove", ruler.onMouseMove);
  88. ruler.doc.unbind("mouseup", ruler.onMouseUp);
  89. ruler.doc.unbind("selectstart", ruler.onSelect);
  90. ruler.drawRuler(e);
  91. },
  92. onSelect: function (e) {
  93. return false;
  94. },
  95. getCount: function(end) {
  96. var start = ruler.ruler.offset().left+1;
  97. var c = Math.max((end - start), ruler.minWidth);
  98. c = Math.min(c, ruler.maxWidth);
  99. return {width:c, count:(c - ruler.minWidth)*ruler.stepCount + ruler.minCount};
  100. },
  101. drawRuler: function(e, animate) {
  102. var c = ruler.getCount(e.clientX);
  103. ruler.cursor.stop();
  104. if ($.browser.msie || !animate) {
  105. ruler.cursor.css({width:c.width});
  106. } else {
  107. ruler.cursor.animate({width:c.width}, {duration: "fast",easing: "swing", complete:null});
  108. }
  109. ruler.count = c.count;
  110. ruler.cursor.text(c.count);
  111. }
  112. }
  113. var showNodeCount = 0;
  114. function onNodeCreated(event, treeId, treeNode) {
  115. showNodeCount++;
  116. }
  117. function createTree () {
  118. var zNodes = dataMaker(ruler.count);
  119. showNodeCount = 0;
  120. $("#treeDemo").empty();
  121. setting.check.enable = $("#showChk").attr("checked");
  122. var time1 = new Date();
  123. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  124. var time2 = new Date();
  125. alert("节点共 " + zNodes.length + " 个, 初始化生成 DOM 的节点共 " + showNodeCount + " 个"
  126. + "\n\n 初始化 zTree 共耗时: " + (time2.getTime() - time1.getTime()) + " ms");
  127. }
  128. $(document).ready(function(){
  129. ruler.init("ruler");
  130. $("#createTree").bind("click", createTree);
  131. });
  132. //-->
  133. </SCRIPT>
  134. </HEAD>
  135. <BODY>
  136. <h1>一次性加载大数据量</h1>
  137. <h6>[ 文件路径: bigdata/common.html ]</h6>
  138. <div class="content_wrap">
  139. <div class="zTreeDemoBackground left">
  140. <ul>
  141. <li><span>调整总节点数,测试加载速度:</span>
  142. <div id="ruler" class="ruler" title="拖拽可调整节点数">
  143. <div id="cursor" class="cursor">5000</div>
  144. </div>
  145. <div style="width:220px; text-align: center;">
  146. <span>checkbox</span><input type="checkbox" id="showChk" title="是否显示 checkbox" class="checkbox first" />&nbsp;&nbsp;&nbsp;&nbsp;
  147. [ <a id="createTree" href="#" title="初始化 zTree" onclick="return false;">初始化 zTree</a> ]
  148. </div>
  149. </li>
  150. </ul>
  151. <ul id="treeDemo" class="ztree"></ul>
  152. </div>
  153. <div class="right">
  154. <ul class="info">
  155. <li class="title"><h2>1、大数据量加载说明</h2>
  156. <ul class="list">
  157. <li>1)、zTree v3.x 针对大数据量一次性加载进行了更深入的优化,实现了延迟加载功能,即不展开的节点不创建子节点的 DOM。</li>
  158. <li class="highlight_red">2)、对于每级节点最多一百左右,但总节点数几千甚至几万,且不是全部展开的数据,一次性加载的效果最明显,速度非常快。</li>
  159. <li class="highlight_red">3)、对于某一级节点数就多达几千的情况 延迟加载无效,这种情况建议考虑分页异步加载。</li>
  160. <li class="highlight_red">4)、对于全部节点都展开显示的情况,延迟加载无效,这种情况建议不要全部展开。</li>
  161. <li>5)、显示 checkbox / radio 会造成一定程度的性能下降。</li>
  162. <li>6)、利用 addDiyDom 功能增加自定义控件会影响速度,影响程度受节点数量而定。</li>
  163. <li>7)、利用 onNodeCreated 事件回调函数对节点 DOM 进行操作会影响速度,影响程度受节点数量而定。</li>
  164. </ul>
  165. </li>
  166. <li class="title"><h2>2、setting 配置信息说明</h2>
  167. <ul class="list">
  168. <li>不需要进行特殊的配置</li>
  169. </ul>
  170. </li>
  171. <li class="title"><h2>3、treeNode 节点数据说明</h2>
  172. <ul class="list">
  173. <li>对 节点数据 没有特殊要求,用户可以根据自己的需求添加自定义属性</li>
  174. </ul>
  175. </li>
  176. </ul>
  177. </div>
  178. </div>
  179. </BODY>
  180. </HTML>