【发布时间】:2020-12-16 22:11:11
【问题描述】:
我有一个存储在数据库中的订单列表。我使用每个块来显示所有带有删除按钮的订单。当我单击删除按钮时,我需要获取 CLICKED 列表项的 ID,以便我可以在数据库中查看该订单并将其删除。我不知道如何获取 CLICKED 列表项的 id 并将其传递给handledelete 函数。我如何在 svelte/sapper 中做到这一点?
显示所有订单页面的代码:
<script>
let orderz =[]
function handlesave() {
//save all the order data to db...
} // handlesave
function handleDelete () {
fetch('order', {
method: 'POST',
credentials : 'include',
headers: {
'Accept': 'application/json',
'Content-type' : 'application/json'
},
body: JSON.stringify({
// order id to send it to server to delete it from the db
})
}).then(response => response.json())
.then(responseJson => {
console.log("xxxxxxx:", responseJson.orderdetails )
})
.catch(error => console.log(error));
}
</script>
<form on:submit|preventDefault={handlesave}>
<button type="submit">Place Order</button>
</form>
<ul>
{#each orderz as order}
<li >
<p >{order.vendorid} - {order.vendorname} - {order.item}
- {order.price}</p>
<button on:click|once={handleDelete}>Delete</button>
</li>
{/each}
</ul>
【问题讨论】: