Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // 每次按下 submit 後觸發此 function 並重讀、顯示一次 populateList function裡的東西
  2. function addItem(e) {
  3. // 以上略
  4. items.push(item);
  5. // 要比 items.push(item); 晚執行,不然不會有新資料
  6. populateList(items, itemsList);
  7. this.reset();
  8. }
  9.  
  10. // plates = [], 避免 items 有問題時卡住不動
  11. function populateList(plates = [], platesList) {
  12. // 利用 map 取出資料(這時是個 big~string~)配合 join 將資料串再一起,顯示在 HTML
  13. platesList.innerHTML = plates.map((plate, i) => {
  14. // id 將 input & label 之間的關係連接起來
  15. return `
  16. <li>
  17. <input type="checkbox" data-index=${i} id="item${i}" ${plate.done ? "checked" : ""}/>
  18. <label for="item${i}">${plate.text}</label>
  19. </li>
  20. `;
  21. }).join("");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement