简体   繁体   English

在Dojo中的“确认”对话框上注销执行中操作

[英]Unregistering On-Execute Action on a Confirm Dialog in Dojo

I have a dojo widget as below: 我有一个dojo小部件,如下所示:

define("myWidget/AnExperiment", [
    "dojo/_base/declare",
    "dojo/dom-style",
    "dijit/ConfirmDialog",
    "dijit/_WidgetBase"
    ], function(declare, domStyle, ConfirmDialog, _WidgetBase) {

return declare([_WidgetBase], {

myDialog: null,

createDialog: function() {
self = this;

self.myDialog = new ConfirmDialog({
                title: 'MyDialog',
                content: 'This is my Dialog.',
                closable: false
            });

domStyle.set(myDialog.cancelButton.domNode, "display", "none");

self.myDialog.on("execute", function() {
                console.log('Func1 called');
                self.myFunc1();
            });

self.myDialog.show();

setTimeout(function() {
                self.changeDialogAction();
            }, 30000);

}

changeDialogAction: function () {
    var self = this;
    self.myDialog.set("title", 'Changed MyDialog');
    self.myDialog.set("content", 'This is the changed dialog');
    // WHAT DO I DO HERE TO UN-REGISTER OLD ON-EXECUTE ACTION
    self.myDialog.on("execute", function() {
        console.log('Func2 called');
                self.myFunc2();
    });
},

myFunc1: function() {
 console.log('This is func1');
},

myFunc2: function() {
 console.log('This is func2');
}
}   

On invoking createDialog , a ConfirmDialog gets created. 在调用createDialog ,将创建一个ConfirmDialog It is initially configured to call Func1 on-execute . 最初将其配置为on-execute调用Func1 The Dialog is then shown. 然后显示Dialog

However, if the user does not do anything for 30 secs, the on-execute action gets changed to call Func2 . 但是,如果用户在30秒钟内不执行任何操作,则on-execute操作将更改为调用Func2

My problem is, when the user clicks after 30 secs, instead of just Func2 getting called, both Func1 and Func2 gets called. 我的问题是,当用户在30秒后单击时,不仅调用了Func2 ,还调用了Func1Func2

How do I un-register so that only Func2 gets called if the execute happens after 30 secs? 如果执行时间在30秒之后,如何取消注册,以便仅调用Func2

From documentation "The return value of on() provides a method that can be used to remove the event listener from the event." 来自文档“ on()的返回值提供了一种可用于从事件中删除事件侦听器的方法。”

Ex: 例如:

require(["dojo/on", "dojo/_base/window"], function(on, win){
  var signal = on(win.doc, "click", function(){
    // remove listener after first event
    signal.remove();
    // do something else...
  });
});

so once function1 is called, you can use the handler (signal) to remove it. 因此,一旦调用function1,就可以使用处理程序(信号)将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM