Ionic 如何在移除物品后更新离子滑道?

33qvvth1  于 2022-12-16  发布在  Ionic
关注(0)|答案(1)|浏览(130)

我在离子幻灯片中有一个卡片列表,每张卡片都有一个关闭图标来删除它。

<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);
        .....
        }

数据服务服务.服务.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();"重新加载了从登录开始的所有页面,你能建议一个解决这个问题的方法吗?

b4lqfgs4

b4lqfgs41#

采用拼接的方法解决了这一问题

this.cart.splice(index, 1);

相关问题