【发布时间】:2022-08-17 20:23:32
【问题描述】:
我在 ion-slide 中有一张卡片列表,每张卡片都有一个关闭图标来删除它。
<ion-slides >
<ion-slide *ngFor=\"let item of cart; let i = index\" >
<ion-card>
<ion-img src=\'close.png\' (click)=\"removeData(item)\" ></ion-img>
</ion-card>
</ion-slide>
</ion-slides>
主页.ts
async removeData(object) {
.......
// get the index of object
this.dataservice.removeItem(index);
.....
}
数据服务服务.service.ts
removeItem(index) {
return this.getAllItems().then((result) => {
if (result) {
result.splice(index, 1);
return this.storage.set(\'i\', result);
}
});
}
移除卡片后,我希望更新列表或刷新当前页面。我在 removeItem 函数中尝试过
\"this.router.navigate([\"/home\"]);\" 但没有任何改变,\"window.location.reload();\" 从登录开始重新加载所有页面。
您能否提出解决问题的方法?
-
在 removeData 中传递索引并检查此代码
this.cart[index]. splice(index,1) -
@RaviAshara 你能把它写成答案吗?能够接受