我在功能上有删除按钮。当我单击DELETE时,将调用下面的函数并出现Confirm对话框,如果选择OK,则应删除文档,如果我取消,则应取消该文档。
console.log("before confirm dialog");
myDialog = new ConfirmDialog({
title: "ConfirmDialog",
content: "Are you sure? You want to delete document.",
style: "width: 400px, color: green",
onCancel: function(){
//Called when user has pressed the Dialog's cancel button, to notify container.
console.log("cancel");
},
onExecute: function(){
//Called when user has pressed the dialog's OK button, to notify container.
console.log("OK----");
// getting error undefined for this function. How to call this ?
this.onClickResetButton();
}
});
myDialog.show();
};
答案 0 :(得分:0)
this.onClickResetButton() method inside `onExecute` is undefined because 'this' refers to the context of your dialog. i.e. it thinks that `onClickResetButton()` is a method which is part of `ConfirmDialog`
克服此问题的一种方法是定义一个变量(可以在构造函数中或在postCreate中)并为其分配“ this”
例如:let widgetRef=this;
稍后您可以在“ widgetRef.onClickResetButton()
”内使用onExecute