From 9ed72aa23e98aaccee17ec8b027ec2765a07e33c Mon Sep 17 00:00:00 2001 From: Tim Aldinger Date: Tue, 13 Oct 2026 23:09:25 +0200 Subject: [PATCH] =?UTF-8?q?=C3=A4ndern=20von=20name=20und=20amount=20erfol?= =?UTF-8?q?gt=20=C3=BCber=20attributen=C3=A4nderung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit attributChangedCallback wird ausgelöst wenn sich ein attribut in observedAttributes von shopping-item ändert --- .../resources/static/js/models/ShoppingItem.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/js/models/ShoppingItem.js b/src/main/resources/static/js/models/ShoppingItem.js index 5d35971..f88aa1a 100644 --- a/src/main/resources/static/js/models/ShoppingItem.js +++ b/src/main/resources/static/js/models/ShoppingItem.js @@ -1,5 +1,6 @@ export class ShoppingItem extends HTMLElement { + static get observedAttributes() { return ["item-name", "item-amount"] } constructor() { super(); this._rendered = false; @@ -40,8 +41,19 @@ export class ShoppingItem extends HTMLElement { } - attributeChangedCallback() { - + attributeChangedCallback(name, oldVal, newVal) { + if (!this._rendered) return; + if (newVal == oldVal) return; + switch (name) { + case "item-name": + this.querySelector(".item__itemName").textContent = newVal; + break; + case "item-amount": + this.querySelector(".item__itemAmount").textContent = newVal; + break; + default: + break; + } } }