<script lang="ts"> import type { PageData } from "./$types"; import { onMount } from…
- User
{#if selectedItems?.length > 0} {#each selectedItems as item, index (item)} <!-- Product #1 --> <div class="item"> <div class="buttons"> <button class="delete-btn" on:click={remove item}></button> </div> <div class="avatar"> {#if item.Bild} <div class="scale-150"> <img src={URL.createObjectURL( new Blob([Buffer.from(item.Bild.data, "base64")]), )} alt="" /> </div> {/if} </div> <div class="description"> <span>{item.Name}</span> <span>Beschreibung1</span> </div> <div class="quantity"> <button class="plus-btn" type="button" name="button" on:click={() => incrementCounter(index)} > <img src="/plus.svg" alt="" /> </button> <input type="text" name="name" bind:value={selectedItemCountsInt[index]} /> <button class="minus-btn" type="button" name="button" on:click={() => decrementCounter(index)} > <img src="/minus.svg" alt="" /> </button> </div> <div class="total-price">{item.Preis + "€"}</div> </div> {/each} <div style="display: flex; justify-content: flex-end;"> Gesamt: {summe}€</div> <div> <textarea class="textarea" placeholder="Anmerkungen hinzufügen" style="margin-left: 4%;" bind:value={anmerkung}></textarea> </div> {:else} <span>Ihr Warenkorb ist leer</span> {/if} <div style="display: flex; justify-content: flex-end;"> <button class="btn btn-primary" type="button" on:click={()=> {submitOrder(); goto("/bestellhistorie");}}>Bestellen</button> </div>please immplement a delete item function for the delete button
- Assistant
To implement a delete item function, we need to remove an item from the
selectedItemsarray and also update theselectedItemIDsandselectedItemCountsto reflect this change. To make that possible, first ensure you have a unique way to identify each item—typically, this would be anidor similar property.Below is an implementation of the
deleteItemfunction, which you should add to your script: