gpt4 book ai didi

popup - Ionic 3 确认弹出窗口从列表中删除项目

转载 作者:行者123 更新时间:2023-12-01 11:18:01 28 4
gpt4 key购买 nike

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

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

在我的 .ts 中我有这段代码:

this.items = [
{user: 'UserA'},
{user: 'UserB'}
];

remove(no) {
(this.items).splice(no, 1);
}

我的问题是,现在,当用户单击按钮时,调用顶部打开弹出窗口的方法:

<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 方法中编写一个单独的删除函数?我该怎么做呢?抱歉,这里很新,非常感谢任何帮助!

最佳答案

在您的 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);
}
}
]
})
}

关于popup - Ionic 3 确认弹出窗口从列表中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48143891/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com