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