addNewItem berücksichtig jetzt, ob Gegenstand zu einer Kategorie gehört oder nicht

This commit is contained in:
Technoir committed 2026-09-29 12:00:05 +02:00
1 parent ce93c7a56e
commit 4af57ba1de
1 file changed
+8 -2
+8 -2
View File
@@ -1,4 +1,5 @@
import { ShoppingListItem } from "./ShoppingListItem";
import { ShoppingCategory } from "./ShoppingCategory";
const addItemForm = document.querySelector(".list__form__addItem");
const addCategoryForm = document.querySelector(".list__form__addCategory")
@@ -12,8 +13,13 @@ function addCategory() {
}
function addNewItem(itemName, itemAmount, category) {
listElements.push(new ShoppingListItem(itemName, itemAmount, category, renderList));
renderList();
if (category) {
category = listElements.find((element) => element instanceof ShoppingCategory && element.categoryName == category)
category.addItem(new ShoppingListItem(itemName, itemAmount, renderItemList));
} else {
listElements.push(new ShoppingListItem(itemName, itemAmount, renderItemList));
}
renderItemList();
return 0;
}