zTreeObj.addNodes.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <div class="apiDetail">
  2. <div>
  3. <h2><span>Function(parentNode, [index], newNodes, isSilent)</span><span class="path">zTreeObj.</span>addNodes
  4. </h2>
  5. <h3>Overview<span class="h3_info">[ depends on <span
  6. class="highlight_green">jquery.ztree.core</span> js ]</span></h3>
  7. <div class="desc">
  8. <p></p>
  9. <div class="longdesc">
  10. <p>Add nodes</p>
  11. <p class="highlight_red">In order to avoid duplication data resulting from repeated initialization,
  12. zTree v3.x will automatically clone node data when zTree initialized or add nodes. If you need to
  13. get the data objects within the zTree, please get the return value of this method.</p>
  14. <p class="highlight_red">Please use zTree object to executing the method.</p>
  15. </div>
  16. </div>
  17. <h3>Function Parameter Descriptions</h3>
  18. <div class="desc">
  19. <h4><b>parentNode</b><span>JSON</span></h4>
  20. <p>The additional node's parent node. If additional node is root node, please the parentNode is null.</p>
  21. <p class="highlight_red">Please ensure this node data object is a data object within zTree.</p>
  22. <h4><b>[index]</b><span>Number</span></h4>
  23. <p>The index of the parentNode's children where the newnodes will be added (the value start from 0)</p>
  24. <p>When index = -1, the newnodes will be added to the last</p>
  25. <p>This parameter can be ignore.</p>
  26. <p class="highlight_red">v3.5.19+</p>
  27. <h4 class="topLine"><b>newNodes</b><span>JSON / Array(JSON)</span></h4>
  28. <p>The node data's JSON object collection which need to increase, refer to 'treeNode treeNode data
  29. details'</p>
  30. <p class="highlight_red">1. zTree v3.x support to add single node, that is, if you only add a node, you can
  31. don't use the array.</p>
  32. <p class="highlight_red">2. If you use simple data model, please refer to the attributes within the
  33. 'setting.data.simpleData'.</p>
  34. <h4 class="topLine"><b>isSilent</b><span>Boolean</span></h4>
  35. <p>Set whether to automatically expand the parent node, after add nodes.</p>
  36. <p>isSilent = true means: don't auto expand the parent node. Otherwise auto expand.</p>
  37. <h4 class="topLine"><b>Return </b><span>Array(JSON)</span></h4>
  38. <p>return the new nodes in zTree</p>
  39. <p class="highlight_red">If the newNodes is single data object, the return value is a array with length is
  40. 1.</p>
  41. <p class="highlight_red">Note: the node data JSON object in the return value is not equal to the JSON object
  42. in the 'newNodes'.</p>
  43. </div>
  44. <h3>Examples of function</h3>
  45. <h4>1. Add one root node to zTree which id is 'tree'</h4>
  46. <pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
  47. var newNode = {name:"newNode1"};
  48. newNode = treeObj.addNodes(null, newNode);
  49. </code></pre>
  50. <h4>2. Add three root nodes to zTree which id is 'tree'</h4>
  51. <pre xmlns=""><code>var treeObj = $.fn.zTree.getZTreeObj("tree");
  52. var newNodes = [{name:"newNode1"}, {name:"newNode2"}, {name:"newNode3"}];
  53. newNodes = treeObj.addNodes(null, newNodes);
  54. </code></pre>
  55. </div>
  56. </div>