zTreeObj.transformTozTreeNodes.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <div class="apiDetail">
  2. <div>
  3. <h2><span>Function(simpleNodes)</span><span class="path">zTreeObj.</span>transformTozTreeNodes</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>Transform the simple array into zTree nodes data.</p>
  9. <p class="highlight_red">If you use this method, you must set 'setting.data.simpleData.idKey' and 'setting.data.simpleData.pIdKey' attribute, and let the data are consistent with parent-child relationship.</p>
  10. <p class="highlight_red">Please use zTree object to executing the method.</p>
  11. </div>
  12. </div>
  13. <h3>Function Parameter Descriptions</h3>
  14. <div class="desc">
  15. <h4><b>simpleNodes</b><span>Array(JSON) / JSON</span></h4>
  16. <p>JSON data object of the node which need to be transformed.</p>
  17. <p>or JSON data objects array of the nodes which need to be transformed.</p>
  18. <h4 class="topLine"><b>Return </b><span>Array(JSON)</span></h4>
  19. <p>Standard data which zTree use. The child nodes are stored in the parent node's 'children' attribute.</p>
  20. <p class="highlight_red">If simpleNodes is a single JSON, so the return array's length is 1.</p>
  21. </div>
  22. <h3>Examples of function</h3>
  23. <h4>1. Transform the simple array data into zTree nodes format.</h4>
  24. <pre xmlns=""><code>var setting = {
  25. data: {
  26. simpleData: {
  27. enable: true,
  28. idKey: "id",
  29. pIdKey: "pId",
  30. rootPId: 0
  31. }
  32. }
  33. };
  34. var simpleNodes = [
  35. {"id":1, "pId":0, "name":"test1"},
  36. {"id":11, "pId":1, "name":"test11"},
  37. {"id":12, "pId":1, "name":"test12"},
  38. {"id":111, "pId":11, "name":"test111"}
  39. ];
  40. var treeObj = $.fn.zTree.getZTreeObj("tree");
  41. var nodes = treeObj.transformTozTreeNodes(simpleNodes);
  42. </code></pre>
  43. </div>
  44. </div>