san*_*a-p 4 javascript undo toast ionic2 angular
我用ionic2创建了一个toast(+ angular2 with javascript,而不是typescript),用户从列表中删除了一个项目.
到目前为止Undo一切都很好,现在我想在吐司里面添加一个按钮(替换为Undo),将它放回到列表中并同时解除吐司.
我的代码到目前为止:
archiveItem(item) {
let toast = Toast.create({
message: 'Item archived.',
duration: 2000,
showCloseButton: true,
closeButtonText: 'Undo',
dismissOnPageChange: true,
});
var index = this.items.indexOf(item);
this.items.splice(index, 1); //remove the item
toast.onDismiss(() => {
console.log('Dismissed toast');
this.items.splice(index, 0, item); //put back the item on right place
});
this.nav.present(toast);
}
Run Code Online (Sandbox Code Playgroud)
单击时Undo,该项目返回列表,问题是如果我不单击它,它也会返回到列表.
我想我需要创建另一个函数Undo,但我不知道该怎么做,Ionic2 DOCS不会谈论它...
谢谢 :)
Man*_*dés 12
编辑:
试试这个:
toast.onDismiss((data, role) => {
console.log('Dismissed toast');
if (role== "close") {
this.items.splice(index, 0, item); //put back the item on right place
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:为了清晰起见重命名参数
| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |