edit.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - edit</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. },
  18. data: {
  19. simpleData: {
  20. enable: true
  21. }
  22. },
  23. callback: {
  24. beforeDrag: beforeDrag
  25. }
  26. };
  27. var zNodes =[
  28. { id:1, pId:0, name:"parent node 1", open:true},
  29. { id:11, pId:1, name:"leaf node 1-1"},
  30. { id:12, pId:1, name:"leaf node 1-2"},
  31. { id:13, pId:1, name:"leaf node 1-3"},
  32. { id:2, pId:0, name:"parent node 2", open:true},
  33. { id:21, pId:2, name:"leaf node 2-1"},
  34. { id:22, pId:2, name:"leaf node 2-2"},
  35. { id:23, pId:2, name:"leaf node 2-3"},
  36. { id:3, pId:0, name:"parent node 3", open:true },
  37. { id:31, pId:3, name:"leaf node 3-1"},
  38. { id:32, pId:3, name:"leaf node 3-2"},
  39. { id:33, pId:3, name:"leaf node 3-3"}
  40. ];
  41. function beforeDrag(treeId, treeNodes) {
  42. return false;
  43. }
  44. function setEdit() {
  45. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  46. remove = $("#remove").attr("checked"),
  47. rename = $("#rename").attr("checked"),
  48. removeTitle = $.trim($("#removeTitle").get(0).value),
  49. renameTitle = $.trim($("#renameTitle").get(0).value);
  50. zTree.setting.edit.showRemoveBtn = remove;
  51. zTree.setting.edit.showRenameBtn = rename;
  52. zTree.setting.edit.removeTitle = removeTitle;
  53. zTree.setting.edit.renameTitle = renameTitle;
  54. showCode(['setting.edit.showRemoveBtn = ' + remove, 'setting.edit.showRenameBtn = ' + rename,
  55. 'setting.edit.removeTitle = "' + removeTitle +'"', 'setting.edit.renameTitle = "' + renameTitle + '"']);
  56. }
  57. function showCode(str) {
  58. var code = $("#code");
  59. code.empty();
  60. for (var i=0, l=str.length; i<l; i++) {
  61. code.append("<li>"+str[i]+"</li>");
  62. }
  63. }
  64. $(document).ready(function(){
  65. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  66. setEdit();
  67. $("#remove").bind("change", setEdit);
  68. $("#rename").bind("change", setEdit);
  69. $("#removeTitle").bind("propertychange", setEdit)
  70. .bind("input", setEdit);
  71. $("#renameTitle").bind("propertychange", setEdit)
  72. .bind("input", setEdit);
  73. });
  74. //-->
  75. </SCRIPT>
  76. </HEAD>
  77. <BODY>
  78. <h1>Basic Edit Nodes</h1>
  79. <h6>[ File Path: exedit/edit.html ]</h6>
  80. <div class="content_wrap">
  81. <div class="zTreeDemoBackground left">
  82. <ul id="treeDemo" class="ztree"></ul>
  83. </div>
  84. <div class="right">
  85. <ul class="info">
  86. <li class="title"><h2>1, Explanation of setting</h2>
  87. <ul class="list">
  88. <li>This Demo only shows how to edit nodes using the basic method and configure parameters.</li>
  89. <li class="highlight_red">1) Must set 'setting.edit' attributes, see the API documentation for more related contents.</li>
  90. <li class="highlight_red">2) If you want to use remove / rename callback, muse to set 'setting.callback.beforeRemove / onRemove / beforeRename / onRename' attributes, see the API documentation for more related contents.</li>
  91. <li class="highlight_red">3) zTree do not provide buttons for add nodes, please use the custom control methods 'addHoverDom / removeHoverDom' to achieve added functionality, see the API documentation for more related contents. Another way, you can see the demo named 'Advanced Edit Nodes'.</li>
  92. <li><p>Edit button setting:<br/>
  93. <input type="checkbox" id="remove" class="checkbox first" checked /><span>show remove button</span>
  94. <input type="checkbox" id="rename" class="checkbox " checked /><span>show edit button</span><br/>
  95. title for remove: <input type="text" id="removeTitle" value="remove" /><br/>
  96. title for rename: <input type="text" id="renameTitle" value="rename" />
  97. <ul id="code" class="log" style="height:85px;"></ul></p>
  98. </li>
  99. </ul>
  100. </li>
  101. <li class="title"><h2>2, Explanation of treeNode</h2>
  102. <ul class="list">
  103. <li>No special requirements on the node data, the user can add custom attributes.</li>
  104. </ul>
  105. </li>
  106. </ul>
  107. </div>
  108. </div>
  109. </BODY>
  110. </HTML>