代码之家  ›  专栏  ›  技术社区  ›  KatherineMichelle

离子3确认弹出窗口从列表中删除项目

  •  3
  • KatherineMichelle  · 技术社区  · 7 年前

    我有一个用户可以删除其他用户的应用程序。当用户单击删除按钮时,会出现一个弹出窗口,询问用户是否确定要执行此操作。当用户单击“确认”时,我希望删除该用户。 之前,我通过在按钮上放置一个remove方法实现了这一点,如下所示:

    <button ion-button (click)="remove(i);">Delete</button>
    

    在我的。ts我有以下代码:

    this.items = [
                  {user: 'UserA'},
                  {user: 'UserB'}
              ];
    
      remove(no) {
        (this.items).splice(no, 1);
      }
    

    我的问题是,现在,当用户单击按钮时,会调用top open the popup方法:

    <button ion-button (click)="showConfirmAlert();">Delete</button>
    

    现在我不知道如何从列表中删除该项目。

    showConfirmAlert() {
            let alert = this.alertCtrl.create({
                title: 'Confirm delete user',
                message: 'Are you sure you want to permanently delete this user?',
                buttons: [
                    {
                        text: 'No',
                        handler: () => {
                            console.log('Cancel clicked');
                        }
                    },
                    {
                        text: 'Yes',
                        handler: () => {
    
                        }
                    }
                ]
            })
          }
    

    我是否需要在showConfirmAlert方法中编写一个单独的remove函数?我该怎么做呢?对不起,这里很新,如果您有任何帮助,我们将不胜感激!

    1 回复  |  直到 7 年前
        1
  •  5
  •   Husain    7 年前

    在html文件中:

    <button ion-button (click)="showConfirmAlert(i);">Delete</button>
    

    在ts文件中:

    showConfirmAlert(i) {
        let alert = this.alertCtrl.create({
            title: 'Confirm delete user',
            message: 'Are you sure you want to permanently delete this user?',
            buttons: [
                {
                    text: 'No',
                    handler: () => {
                        console.log('Cancel clicked');
                    }
                },
                {
                    text: 'Yes',
                    handler: () => {
                       this.items.splice(i,1);
                    }
                }
            ]
        })
      }