Javascript X 上的 Dojo 对话框关闭事件(右上角)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10173508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:10:02  来源:igfitidea点击:

Dojo dialog close event on X (top-right)

javascriptbuttondojodialog

提问by Thor A. Pedersen

Im using Dojo to create a simple dialog to create a user in a system. The problem is I get the error:

我使用 Dojo 创建一个简单的对话框来在系统中创建用户。问题是我收到错误:

Tried to register widget with `id==user_submit` but that `id` is already registered

user_submit, is a Dojo button I have to finish the form inside the dialog. When I close the dialog by clicking it and submitting the form there is no problem in opening the dialog again (in the click event on the button I have this line of code:

user_submit, 是一个 Dojo 按钮,我必须在对话框内完成表单。当我通过单击关闭对话框并提交表单时,再次打开对话框没有问题(在按钮上的单击事件中,我有以下代码行:

dijit.byId("user_submit").destroy();

but if I close the dialog through the [x]-link / button in the top-right corner I don't destroy the button and then can't open the dialog again without reloading the page.

但是如果我通过右上角的 [x]-link / 按钮关闭对话框,我不会破坏按钮,然后在不重新加载页面的情况下无法再次打开对话框。

How do I get Dojo to destroy the button or how to a overload the click-event on [X]-link / button, so I can write the destroy command for the button?

如何让 Dojo 销毁按钮或如何重载 [X] 链接/按钮上的点击事件,以便我可以为按钮编写销毁命令?

采纳答案by Thor A. Pedersen

Found a solution. by using dojo.connect().

找到了解决办法。通过使用 dojo.connect()。

myDialog.connect(myDialog, "hide", function(e){
    dijit.byId("user_submit").destroy(); 
});

Would have postet this shortly after i posted the quistion, but I didn't have enough points, so here is the answer again, just a little late :-)

在我发布问题后不久就会发布这个,但我没有足够的积分,所以这里是答案,只是有点晚了:-)

回答by user3489215

"Developer shouldn't override or connect to this method"for "onCancel" see documentation. A better solution is:

"Developer shouldn't override or connect to this method"对于“onCancel”,请参阅文档。更好的解决方案是:

var myDialog = new Dialog({
   id: "myDialogId1",
   onHide: function() {
      myDialog.destroy()
   }
});

回答by hugomg

IIRC, the onCloseextension event gets called when you click on the X thing, so you could try putting your cleanup code there.

IIRC,onClose当您单击 X 事物时会调用扩展事件,因此您可以尝试将清理代码放在那里。



You could also consider sidesteping the issue entirely. Perhaps you don't need to destroy the widget and could instead reuse the same one? You could also do a widget existence test before you create it again, destroying the old version if its still alive.

你也可以考虑完全回避这个问题。也许您不需要销毁小部件,而是可以重用相同的小部件?您还可以在再次创建之前进行小部件存在测试,如果旧版本仍然存在,则销毁旧版本。

回答by Neelesh

You can override onCancel()method as stated above or you can attach event to the dijit.dialog.closeButtonNodedomElement. dijit.dialog.closeButtonNodeis the name of data-dojo-attach-pointattribute for close button.

您可以onCancel()如上所述覆盖方法,也可以将事件附加到 dijit.dialog.closeButtonNodedomElement。 dijit.dialog.closeButtonNodedata-dojo-attach-point关闭按钮的属性名称。

Exp:

经验:

dojo.on(dijit.Dialog.closeButtonNode, "click", function(evt){
      //add your logic here
});

回答by Nick Hermans

When pressing the X on the top of the dialog the "onCancel" event is triggered.

当按下对话框顶部的 X 时,将触发“onCancel”事件。

Dispose of the element there.

在那里处理元素。