fn.zTree.init.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <div class="apiDetail">
  2. <div>
  3. <h2><span>Function(obj, zSetting, zNodes)</span><span class="path">$.fn.zTree.</span>init</h2>
  4. <h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jquery.ztree.core</span> js ]</span></h3>
  5. <div class="desc">
  6. <p></p>
  7. <div class="longdesc">
  8. <p>This method is used to create a zTree.</p>
  9. <p>1. The web page must use the W3C DTD. For example: &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&nbsp;&nbsp; &nbsp;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;</p>
  10. <p>2. Needs jquery-1.4.2.js or better.</p>
  11. <p>3. Needs jquery-ztree.core-3.0.js or better.
  12. If you are using edit mode or checkbox / radio mode,
  13. make sure you load jquery-ztree.exedit-3.0.js and jquery-ztree.excheck-3.0.js.</p>
  14. <p>4. Needs zTreeStyle.css and image files</p>
  15. <p>5. If you plan to use custom icons, please refer to the Demo,
  16. or see the help on iconSkin.</p>
  17. <p>6. Note: You need to set zTree container's class name to "ztree".
  18. If you need to change it, don't forget to modify the css file.
  19. If you need other special styles, you can modify the css file.</p>
  20. </div>
  21. </div>
  22. <h3>Function Parameter Descriptions</h3>
  23. <div class="desc">
  24. <h4><b>object</b><span>jQuery Object</span></h4>
  25. <p>DOM Container for zTree</p>
  26. <h4 class="topLine"><b>zSetting</b><span>JSON</span></h4>
  27. <p>zTree's configuration data, please refer to "setting details" in the API Document.</p>
  28. <h4 class="topLine"><b>zNodes</b><span>Array(JSON) / JSON</span></h4>
  29. <p>zTree's node data, please refer to "treeNode data details" in the API Document.</p>
  30. <p class="highlight_red">1. zTree v3.x support to add single node, that is, if only to add one node,
  31. you can use JSON without using Array.</p>
  32. <p class="highlight_red">2. If you are planning on using asynchronous loading of root nodes, set it to null or [ ]</p>
  33. <p class="highlight_red">3. If you are using simple data mode, please refer to "setting.data.simpleData" in the API Document.</p>
  34. <h4 class="topLine"><b>Return </b><span>JSON</span></h4>
  35. <p>zTree object</p>
  36. <p>This object can provide the methods of operate the zTree</p>
  37. <p class="highlight_red">You can use $.fn.zTree.getZTreeObj method at any time to obtain.</p>
  38. </div>
  39. <h3>Examples of setting & function</h3>
  40. <h4>1. create a simple tree</h4>
  41. <pre xmlns=""><code>&lt;!DOCTYPE html&gt;
  42. &lt;HTML&gt;
  43. &lt;HEAD&gt;
  44. &lt;TITLE&gt; ZTREE DEMO &lt;/TITLE&gt;
  45. &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
  46. &lt;link rel="stylesheet" href="zTreeStyle/zTreeStyle.css" type="text/css"&gt;
  47. &lt;script type="text/javascript" src="jquery-1.4.2.js"&gt;&lt;/script&gt;
  48. &lt;script type="text/javascript" src="jquery.ztree.core-3.5.js"&gt;&lt;/script&gt;
  49. &lt;!--
  50. &lt;script type="text/javascript" src="jquery.ztree.excheck-3.5.js"&gt;&lt;/script&gt;
  51. &lt;script type="text/javascript" src="jquery.ztree.exedit-3.5.js"&gt;&lt;/script&gt;
  52. --&gt;
  53. &lt;SCRIPT type="text/javascript" &gt;
  54. var zTreeObj,
  55. setting = {
  56. view: {
  57. selectedMulti: false
  58. }
  59. },
  60. zTreeNodes = [
  61. {"name":"Site Map", open:true, children: [
  62. { "name":"google", "url":"http://www.google.com", "target":"_blank"},
  63. { "name":"baidu", "url":"http://baidu.com", "target":"_blank"},
  64. { "name":"sina", "url":"http://www.sina.com.cn", "target":"_blank"}
  65. ]
  66. }
  67. ];
  68. $(document).ready(function(){
  69. zTreeObj = $.fn.zTree.init($("#tree"), setting, zTreeNodes);
  70. });
  71. &lt;/SCRIPT&gt;
  72. &lt;/HEAD&gt;
  73. &lt;BODY&gt;
  74. &lt;ul id="tree" class="ztree" style="width:230px; overflow:auto;"&gt;&lt;/ul&gt;
  75. &lt;/BODY&gt;
  76. &lt;/HTML&gt;</code></pre>
  77. </div>
  78. </div>