nativescript vue dialogs.confirm - 代码不在对话框中执行
nativescript vue dialogs.confirm - code is not executed inside dialogs
我有一个方法"deleteItem"。里面是一个dialogs.confirm的代码块,代码(删除数组键和保存数组)不会被执行。 console.log 被执行并打印 "true"。代码在对话框外运行良好。有任何想法吗?
var dialogs = require("tns-core-modules/ui/dialogs");
...
dialogs.confirm("Delete ?").then(function(result) {
if (result) {
console.log("in deleting: " + result);
// delete item
this.contacts.splice(this.contacts.indexOf(actItem), 1);
// add to ASStore as new array
appSettings.setString("ASStore", JSON.stringify(this.contacts));
}
});
这是上下文,使用箭头函数或在确认对话框上方存储上下文 (this
) 的值并使用引用。
dialogs.confirm("Delete ?").then((result) => {
if (result) {
console.log("in deleting: " + result);
// delete item
this.contacts.splice(this.contacts.indexOf(actItem), 1);
// add to ASStore as new array
appSettings.setString("ASStore", JSON.stringify(this.contacts));
}
});
我有一个方法"deleteItem"。里面是一个dialogs.confirm的代码块,代码(删除数组键和保存数组)不会被执行。 console.log 被执行并打印 "true"。代码在对话框外运行良好。有任何想法吗?
var dialogs = require("tns-core-modules/ui/dialogs");
...
dialogs.confirm("Delete ?").then(function(result) {
if (result) {
console.log("in deleting: " + result);
// delete item
this.contacts.splice(this.contacts.indexOf(actItem), 1);
// add to ASStore as new array
appSettings.setString("ASStore", JSON.stringify(this.contacts));
}
});
这是上下文,使用箭头函数或在确认对话框上方存储上下文 (this
) 的值并使用引用。
dialogs.confirm("Delete ?").then((result) => {
if (result) {
console.log("in deleting: " + result);
// delete item
this.contacts.splice(this.contacts.indexOf(actItem), 1);
// add to ASStore as new array
appSettings.setString("ASStore", JSON.stringify(this.contacts));
}
});