drag.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - drag & drop</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var setting = {
  15. edit: {
  16. enable: true,
  17. showRemoveBtn: false,
  18. showRenameBtn: false
  19. },
  20. data: {
  21. simpleData: {
  22. enable: true
  23. }
  24. },
  25. callback: {
  26. beforeDrag: beforeDrag,
  27. beforeDrop: beforeDrop
  28. }
  29. };
  30. var zNodes =[
  31. { id:1, pId:0, name:"随意拖拽 1", open:true},
  32. { id:11, pId:1, name:"随意拖拽 1-1"},
  33. { id:12, pId:1, name:"随意拖拽 1-2", open:true},
  34. { id:121, pId:12, name:"随意拖拽 1-2-1"},
  35. { id:122, pId:12, name:"随意拖拽 1-2-2"},
  36. { id:123, pId:12, name:"随意拖拽 1-2-3"},
  37. { id:13, pId:1, name:"禁止拖拽 1-3", open:true, drag:false},
  38. { id:131, pId:13, name:"禁止拖拽 1-3-1", drag:false},
  39. { id:132, pId:13, name:"禁止拖拽 1-3-2", drag:false},
  40. { id:133, pId:13, name:"随意拖拽 1-3-3"},
  41. { id:2, pId:0, name:"随意拖拽 2", open:true},
  42. { id:21, pId:2, name:"随意拖拽 2-1"},
  43. { id:22, pId:2, name:"禁止拖拽到我身上 2-2", open:true, drop:false},
  44. { id:221, pId:22, name:"随意拖拽 2-2-1"},
  45. { id:222, pId:22, name:"随意拖拽 2-2-2"},
  46. { id:223, pId:22, name:"随意拖拽 2-2-3"},
  47. { id:23, pId:2, name:"随意拖拽 2-3"}
  48. ];
  49. function beforeDrag(treeId, treeNodes) {
  50. for (var i=0,l=treeNodes.length; i<l; i++) {
  51. if (treeNodes[i].drag === false) {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. function beforeDrop(treeId, treeNodes, targetNode, moveType) {
  58. return targetNode ? targetNode.drop !== false : true;
  59. }
  60. function setCheck() {
  61. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  62. isCopy = $("#copy").attr("checked"),
  63. isMove = $("#move").attr("checked"),
  64. prev = $("#prev").attr("checked"),
  65. inner = $("#inner").attr("checked"),
  66. next = $("#next").attr("checked");
  67. zTree.setting.edit.drag.isCopy = isCopy;
  68. zTree.setting.edit.drag.isMove = isMove;
  69. showCode(1, ['setting.edit.drag.isCopy = ' + isCopy, 'setting.edit.drag.isMove = ' + isMove]);
  70. zTree.setting.edit.drag.prev = prev;
  71. zTree.setting.edit.drag.inner = inner;
  72. zTree.setting.edit.drag.next = next;
  73. showCode(2, ['setting.edit.drag.prev = ' + prev, 'setting.edit.drag.inner = ' + inner, 'setting.edit.drag.next = ' + next]);
  74. }
  75. function showCode(id, str) {
  76. var code = $("#code" + id);
  77. code.empty();
  78. for (var i=0, l=str.length; i<l; i++) {
  79. code.append("<li>"+str[i]+"</li>");
  80. }
  81. }
  82. $(document).ready(function(){
  83. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  84. setCheck();
  85. $("#copy").bind("change", setCheck);
  86. $("#move").bind("change", setCheck);
  87. $("#prev").bind("change", setCheck);
  88. $("#inner").bind("change", setCheck);
  89. $("#next").bind("change", setCheck);
  90. });
  91. //-->
  92. </SCRIPT>
  93. </HEAD>
  94. <BODY>
  95. <h1>拖拽节点基本控制</h1>
  96. <h6>[ 文件路径: exedit/drag.html ]</h6>
  97. <div class="content_wrap">
  98. <div class="zTreeDemoBackground left">
  99. <ul id="treeDemo" class="ztree"></ul>
  100. </div>
  101. <div class="right">
  102. <ul class="info">
  103. <li class="title"><h2>1、setting 配置信息说明</h2>
  104. <ul class="list">
  105. <li>此 Demo 仅从功能上演示实现拖拽的基本方法和配置参数</li>
  106. <li class="highlight_red">1)、使用 拖拽功能,必须设置 setting.edit 中的各个属性,详细请参见 API 文档中的相关内容</li>
  107. <li class="highlight_red">2)、使用 拖拽功能的事件回调函数,必须设置 setting.callback.beforeDrag / onDrag / beforeDrop / onDrop 等属性,详细请参见 API 文档中的相关内容</li>
  108. <li><p>基本拖拽设置:<br/>
  109. <input type="checkbox" id="copy" class="checkbox first" checked /><span>允许复制</span>
  110. <input type="checkbox" id="move" class="checkbox " checked /><span>允许移动</span><br/>
  111. <ul id="code1" class="log" style="height:42px;"></ul></p>
  112. </li>
  113. <li><p>拖拽相对位置设置:<br/>
  114. <input type="checkbox" id="prev" class="checkbox first" checked /><span>prev</span>
  115. <input type="checkbox" id="inner" class="checkbox " checked /><span>inner</span>
  116. <input type="checkbox" id="next" class="checkbox " checked /><span>next</span><br/>
  117. <ul id="code2" class="log" style="height:65px;"></ul></p>
  118. </li>
  119. </ul>
  120. </li>
  121. <li class="title"><h2>2、treeNode 节点数据说明</h2>
  122. <ul class="list">
  123. <li>对 节点数据 没有特殊要求,用户可以根据自己的需求添加自定义属性</li>
  124. </ul>
  125. </li>
  126. </ul>
  127. </div>
  128. </div>
  129. </BODY>
  130. </HTML>