zTreeObj.transformTozTreeNodes.html 2.0 KB

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