setting.callback.beforeDrop.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <div class="apiDetail">
  2. <div>
  3. <h2><span>Function(treeId, treeNodes, targetNode, moveType, isCopy)</span><span
  4. class="path">setting.callback.</span>beforeDrop</h2>
  5. <h3>Overview<span class="h3_info">[ depends on <span
  6. class="highlight_green">jquery.ztree.exedit</span> js ]</span></h3>
  7. <div class="desc">
  8. <p></p>
  9. <div class="longdesc">
  10. <p>Specify callback function to be called before drag-drop of a node, The return value controls the
  11. execution of drag-drop callback.</p>
  12. <p>Default: null</p>
  13. <p class="highlight_red">When a node is dropped, if the drop is not in a valid location, this callback
  14. will not be triggered, and will revert to the original position.</p>
  15. </div>
  16. </div>
  17. <h3>Function Parameter Descriptions</h3>
  18. <div class="desc">
  19. <h4><b>treeId</b><span>String</span></h4>
  20. <p>zTree unique identifier: <b class="highlight_red">treeId</b>, the id of the containing tree.</p>
  21. <h4 class="topLine"><b>treeNodes</b><span>Array(JSON)</span></h4>
  22. <p>A collection of the nodes which has been dragged</p>
  23. <p class="highlight_red">The treeNodes which have been dragged, when copying nodes or moving nodes.</p>
  24. <h4 class="topLine"><b>targetNode</b><span>JSON</span></h4>
  25. <p>JSON data object of the destination node on which treeNodes are being dropped.</p>
  26. <p class="highlight_red">If the treeNodes is the root node, the targetNode = null</p>
  27. <h4 class="topLine"><b>moveType</b><span>String</span></h4>
  28. <p>the relative position of move to the target node</p>
  29. <p class="highlight_red">"inner": will be child of targetNode</p>
  30. <p class="highlight_red">"prev": will be sibling node, and be in front of targetNode</p>
  31. <p class="highlight_red">"next": will be sibling node, and be behind targetNode</p>
  32. <h4 class="topLine"><b>isCopy</b><span>Boolean</span></h4>
  33. <p>the flag used to determine if the drop is to copy or move the node</p>
  34. <p class="highlight_red">true: copy node; false: move node</p>
  35. <h4 class="topLine"><b>Return </b><span>Boolean</span></h4>
  36. <p>return true or false</p>
  37. <p class="highlight_red">If return false, zTree will restore the dragged nodes, and will not trigger the
  38. 'onDrop' callback.</p>
  39. </div>
  40. <h3>Examples of setting & function</h3>
  41. <h4>1. disable to drag nodes to root</h4>
  42. <pre xmlns=""><code>function myBeforeDrop(treeId, treeNodes, targetNode, moveType) {
  43. return !(targetNode == null || (moveType != "inner" && !targetNode.parentTId));
  44. };
  45. var setting = {
  46. edit: {
  47. enable: true
  48. },
  49. callback: {
  50. beforeDrop: myBeforeDrop
  51. }
  52. };
  53. ......</code></pre>
  54. </div>
  55. </div>