Leere itemliste erstellen ohne fehler

  • JavaScript

    Leere itemliste erstellen ohne fehler

    Hallo zusammen

    Ich habe unten einen langen Script hineingetan. Überall wo es ​item: [ null ] steht, soll eine leere item-Liste angefügt werden. Ich habe den Code aus einem Tutorial, aber dieser hatte Beispielelemente drin. Wie kann ich dieses anstellen, sodass es wieder mein kanban-board anzeigt?
    Spoiler anzeigen

    HTML-Quellcode

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8" />
    5. <meta name="viewport" content="width=device-width, initial-scale=1" />
    6. <title>Title</title>
    7. <link rel="stylesheet" href="../dist/jkanban.min.css" />
    8. <link rel="stylesheet" href="../dist/jkanban.min.js" />
    9. <link
    10. href="https://fonts.googleapis.com/css?family=Lato"
    11. rel="stylesheet"
    12. />
    13. <style>
    14. body {
    15. font-family: "Lato";
    16. margin: 0;
    17. padding: 0;
    18. }
    19. #myKanban {
    20. overflow-x: auto;
    21. padding: 20px 0;
    22. }
    23. .success {
    24. background: #00b961;
    25. }
    26. .info {
    27. background: #2a92bf;
    28. }
    29. .warning {
    30. background: #f4ce46;
    31. }
    32. .error {
    33. background: #fb7d44;
    34. }
    35. .custom-button {
    36. background-color: #4CAF50;
    37. border: none;
    38. color: white;
    39. padding: 7px 15px;
    40. margin: 10px;
    41. text-align: center;
    42. text-decoration: none;
    43. display: inline-block;
    44. font-size: 16px;
    45. }
    46. </style>
    47. </head>
    48. <body>
    49. <div id="myKanban"></div>
    50. <button id="addDefault">Add "Default" board</button>
    51. <br />
    52. <button id="addToDo">Add element in "To Do" Board</button>
    53. <br />
    54. <button id="removeBoard">Remove "Done" Board</button>
    55. <br />
    56. <button id="removeElement">Remove "My Task Test"</button>
    57. <script src="../dist/jkanban.js"></script>
    58. <script>
    59. var KanbanTest = new jKanban({
    60. element: "#myKanban",
    61. gutter: "10px",
    62. widthBoard: "450px",
    63. itemHandleOptions:{
    64. enabled: true,
    65. },
    66. click: function(el) {
    67. console.log("Trigger on all items click!");
    68. },
    69. dropEl: function(el, target, source, sibling){
    70. console.log(target.parentElement.getAttribute('data-id'));
    71. console.log(el, target, source, sibling)
    72. },
    73. buttonClick: function(el, boardId) {
    74. console.log(el);
    75. console.log(boardId);
    76. // create a form to enter element
    77. var formItem = document.createElement("form");
    78. formItem.setAttribute("class", "itemform");
    79. formItem.innerHTML =
    80. '<div class="form-group"><textarea class="form-control" rows="2" autofocus></textarea></div><div class="form-group"><button type="submit" class="btn btn-primary btn-xs pull-right">Submit</button><button type="button" id="CancelBtn" class="btn btn-default btn-xs pull-right">Cancel</button></div>';
    81. KanbanTest.addForm(boardId, formItem);
    82. formItem.addEventListener("submit", function(e) {
    83. e.preventDefault();
    84. var text = e.target[0].value;
    85. KanbanTest.addElement(boardId, {
    86. title: text
    87. });
    88. formItem.parentNode.removeChild(formItem);
    89. });
    90. document.getElementById("CancelBtn").onclick = function() {
    91. formItem.parentNode.removeChild(formItem);
    92. };
    93. },
    94. itemAddOptions: {
    95. enabled: true,
    96. content: '+ Add New Card',
    97. class: 'custom-button',
    98. footer: true
    99. },
    100. boards: [
    101. {
    102. id: "_todo",
    103. title: "To Do",
    104. class: "info,good",
    105. dragTo: ["_working"],
    106. item: [ null ]
    107. },
    108. {
    109. id: "_working",
    110. title: "Working",
    111. class: "warning",
    112. item: [ null ]
    113. },
    114. {
    115. id: "_done",
    116. title: "Done",
    117. class: "success",
    118. dragTo: ["_working"],
    119. item: [ null ]
    120. }
    121. ]
    122. });
    123. var toDoButton = document.getElementById("addToDo");
    124. toDoButton.addEventListener("click", function() {
    125. KanbanTest.addElement("_todo", {
    126. title: "Test Add"
    127. });
    128. });
    129. var addBoardDefault = document.getElementById("addDefault");
    130. addBoardDefault.addEventListener("click", function() {
    131. KanbanTest.addBoards([
    132. {
    133. id: "_default",
    134. title: "Kanban Default",
    135. item: [
    136. {
    137. title: "Default Item"
    138. },
    139. {
    140. title: "Default Item 2"
    141. },
    142. {
    143. title: "Default Item 3"
    144. }
    145. ]
    146. }
    147. ]);
    148. });
    149. var removeBoard = document.getElementById("removeBoard");
    150. removeBoard.addEventListener("click", function() {
    151. KanbanTest.removeBoard("_done");
    152. });
    153. var removeElement = document.getElementById("removeElement");
    154. removeElement.addEventListener("click", function() {
    155. KanbanTest.removeElement("_test_delete");
    156. });
    157. var allEle = KanbanTest.getBoardElements("_todo");
    158. allEle.forEach(function(item, index) {
    159. //console.log(item);
    160. });
    161. </script>
    162. </body>
    163. </html>