简体   繁体   English

删除项目列表 ionic slide 3

[英]Delete item list ionic slide 3

I run ionic 3 app on browser, when I slide, and click on delete it redirect on the itemDetails instead to reload the same list without the item deleted我在浏览器上运行 ionic 3 应用程序,当我滑动时,点击删除它重定向到 itemDetails 而不是重新加载相同的列表而不删除项目

<ion-list>
    <ion-item-sliding *ngFor="let item of items" (click)="itemDetails($event, item)" (ionSwipe)="delete(item)">
     <ion-item> 
     {{item.name}}
     </ion-item>

     <ion-item-options>
        <button ion-button expandable (click)="removeItem(item.id)">Delete</button>
     </ion-item-options>
    </ion-item-sliding>
</ion-list>

Try to put the (click)="itemDetails($event, item)" into the ion-item尝试将 (click)="itemDetails($event, item)" 放入 ion-item

<ion-list>
<ion-item-sliding *ngFor="let item of items" (ionSwipe)="delete(item)">
 <ion-item (click)="itemDetails($event, item)"> 
 {{item.name}}
 </ion-item>

 <ion-item-options>
    <button ion-button expandable (click)="removeItem(item.id)">Delete</button>
 </ion-item-options>
</ion-item-sliding>

See working plunkr: https://plnkr.co/edit/FfaUWDxovuS0So5fvHCU?p=preview查看工作 plunkr: https ://plnkr.co/edit/FfaUWDxovuS0So5fvHCU ? p = preview

You done very well my friend but you need to do like this你做得很好,我的朋友,但你需要这样做

<ion-list>
    <ion-item-sliding *ngFor="let item of items; let i=index;" (click)="itemDetails($event, item)">
        <ion-item> 
            {{item.name}}
        </ion-item>

        <ion-item-options>
            <button ion-button expandable (click)="removeItem(i)">Delete</button>
        </ion-item-options>
    </ion-item-sliding>
</ion-list>

and in .ts file you need to write this在 .ts 文件中你需要写这个

public removeItem(index:number){
    let id=yourarraylist[index].id
    //remove logic
}

i think this would be helpful to you我认为这对你有帮助

I added this code to the removeItem function :我将此代码添加到 removeItem 函数中:

this.navCtrl.push(HelloIonicPage, {
      item: item
    });

So it seems to redirect to the main list but it is not the best way i think because reload the page is very slow所以它似乎重定向到主列表,但我认为这不是最好的方式,因为重新加载页面非常慢

You can work with observables and use the aync pipe.您可以使用 observables 并使用 aync 管道。

I am on my smartphone and cant provide examples but there should be enough out there.我在我的智能手机上,无法提供示例,但应该有足够的示例。

Or you could try it with ngzone after deleting to Trigger an ui refresh.或者您可以在删除后使用 ngzone 尝试以触发 ui 刷新。

The problem is the list of items is not getting the updated list.问题是项目列表没有得到更新的列表。 You have get the updated list after deleting it.删除后,您已获得更新的列表。

HTML

<ion-list>
<ion-item-sliding *ngFor="let item of items" (click)="itemDetails($event, item)" (ionSwipe)="delete(item)">
 <ion-item> 
 {{item.name}}
 </ion-item>

 <ion-item-options>
    <button ion-button expandable (click)="removeItem(item.id)">Delete</button>
 </ion-item-options>
</ion-item-sliding>

ts

removeItem(item) {
 `your code`
  loadItems(); #get the updated list
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM