[英]Alertify confirm does not work with Ember js
我試圖制作一個彈出框,以確認您是否要刪除文檔。 如果我嘗試:
if(alertify.confirm("Delete this?')) {
this.store.findRecord('document', docId, {backgroundReload: false}).then((doc) => {
doc.destroyRecord();
alertify.success('Document successfully deleted!');
}
據我所知,它不會在運行刪除代碼之前等待確認,因為alertify.confirm是非阻塞的。 如果我嘗試:
deleteFile(docId) {
alertify.confirm("Are you sure you want to delete this document?", function (e) {
if (e) {
this.store.findRecord('document', docId, {backgroundReload: false}).then((doc) => {
doc.destroyRecord();
alertify.success('Document successfully deleted!');
});
} else {
alertify.error('Something went wrong!');
}
});
}
它確實要求確認,但是刪除代碼不起作用,因為存儲即將出現未定義狀態,因此findRecord不起作用。 我嘗試將商店作為服務注入,但這也不起作用。 有沒有辦法使此確認框起作用?
您可以在函數中使用this
函數,從而引用該函數的this上下文。 您可以使用粗箭頭功能,也可以在外部將其分配給變量。 前者看起來像這樣:
deleteFile(docId) {
alertify.confirm("Are you sure you want to delete this document?", (e) => {
if (e) {
this.store.findRecord('document', docId, {backgroundReload: false}).then((doc) => {
doc.destroyRecord();
alertify.success('Document successfully deleted!');
});
} else {
alertify.error('Something went wrong!');
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.