Implementierung ShoppingListItem in die Liste
Import von ShoppingListItem und ändern der renderList() Methode, so dass über jedes Element iteriert wird und ihre .render() Methode aufgerufen wird
This commit is contained in:
1 parent
32d1e5cbc3
commit
28fd846546
1 file changed
+6
-28
+6
-28
@@ -1,12 +1,12 @@
|
||||
|
||||
import { ShoppingListItem } from "./ShoppingListItem";
|
||||
const form = document.querySelector(".list__inputForm");
|
||||
const itemList = document.querySelector(".list__displayedList");
|
||||
const itemListElement = document.querySelector(".list__displayedList");
|
||||
|
||||
let listItems = []; //list of items that the user has
|
||||
|
||||
|
||||
function handleListElement(itemName, itemAmount,) {
|
||||
listItems.push({ name: itemName, amount: itemAmount });
|
||||
listItems.push(new ShoppingListItem(itemName, itemAmount, renderList));
|
||||
renderList();
|
||||
|
||||
return 0;
|
||||
@@ -15,33 +15,11 @@ function handleListElement(itemName, itemAmount,) {
|
||||
|
||||
|
||||
function renderList() {
|
||||
itemList.innerHTML = ""; //reset innerItemList
|
||||
listItems = listItems.filter(item => !item.remove)
|
||||
itemListElement.innerHTML = ""; //reset innerItemList
|
||||
|
||||
listItems.forEach((element, index) => {
|
||||
const li = document.createElement("li");
|
||||
const removeButton = document.createElement("button");
|
||||
const editButton = document.createElement("button");
|
||||
const doneButton = document.createElement("input");
|
||||
|
||||
doneButton.setAttribute("type", "checkbox");
|
||||
doneButton.addEventListener("change", () => {
|
||||
listItems[index].done = doneButton.checked;
|
||||
});
|
||||
|
||||
editButton.textContent = "Bearbeiten"
|
||||
removeButton.textContent = "Löschen";
|
||||
removeButton.addEventListener("click", () => {
|
||||
listItems.splice(index, 1);
|
||||
renderList();
|
||||
});
|
||||
|
||||
li.textContent = element.name + " " + element.amount;
|
||||
li.appendChild(removeButton);
|
||||
li.appendChild(doneButton);
|
||||
li.appendChild(editButton);
|
||||
|
||||
|
||||
itemList.appendChild(li);
|
||||
itemListElement.appendChild(element.render(index));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user