本文介绍了dojo dijit.Dialog破坏底层错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展dijit.Dialog的类,但只能为我的站点设置默认的功能和按钮。当单击对话框的取消按钮时,将运行以下代码:

  this.actionDialog.destroyRecursive(); 
this.actionDialog.destroy();

nb this.actionDialog = dijit.Dialog



有时(不总是)抛出以下错误:

 未捕获TypeError:无法调用未定义的方法'destroy'
DialogUnderlay.xd.js:8

哪些导致以下对话框不正确显示。我使用的是来自Google API的1.5。我错过了底层代码?



肯答案后抛出的错误:

 动画处理程序中的异常:onEnd 
TypeError:无法读取属性'style'为null

都来自 dojo.xd.js:14 。但是代码仍然正常工作。

解决方案

我还不完全确定问题是什么,除了某些原因 dijit.DialogUnderlay 代码变得困惑。 FWIW,这不会发生在Dojo 1.6。



虽然我正在寻找一些潜在的解决方案,但我似乎不小心发现,避免这个问题可能就像在销毁该对话框之前立即调用 hide(),例如:

  this.actionDialog.hide(); 
this.actionDialog.destroyRecursive();

或者,您可能有兴趣隐藏对话框,然后一旦隐藏动画完成就会摧毁它。 / p>

以下是您可以在Dojo 1.5及更早版本(测试1.3 +)上执行此操作:

 code> dlg.connect(dlg._fadeOut,'onEnd',function(){
this.destroyRecursive();
});
dlg.hide();

在1.6中,fadeOut动画不再暴露在实例上(授予,它在技术上是私有的无论如何),但 onHide 现在触发一旦动画结束(而在它一开始触发之前)。不幸的是,需要一个setTimeout来解决由于在分支中调用 onHide 的其他代码而发生的错误,假设在实例上仍然存在一些不在我们之后(请)。

  dlg.connect(dlg,'onHide',function(){
setTimeout(function(){dlg.destroyRecursive();},0);
});
dlg.hide();

在JSFiddle上看到它:(见为原始错误的问题)


I have a class that extends dijit.Dialog but only to set default functionality and buttons for my site. When clicking the dialog's cancel button the following code is run:

    this.actionDialog.destroyRecursive();
    this.actionDialog.destroy();

nb this.actionDialog = dijit.Dialog

Sometimes (not always) the following error gets thrown:

Uncaught TypeError: Cannot call method 'destroy' of undefined
DialogUnderlay.xd.js:8

Which causes following dialogs to incorrectly display. I am using 1.5 from Google API's. Am I missing something with the underlay code?

Error thrown after Ken's answer:

exception in animation handler for: onEnd
TypeError: Cannot read property 'style' of null

Both from dojo.xd.js:14. But the code still works properly.

解决方案

I'm still not entirely sure what the problem is, other than for some reason dijit.DialogUnderlay code is getting confused. FWIW, this doesn't happen in Dojo 1.6.

While I was poking at some potential solutions, I seemed to accidentally find out that avoiding this problem is perhaps as easy as calling hide() on the dialog immediately before destroying it, e.g.:

this.actionDialog.hide();
this.actionDialog.destroyRecursive();

Alternatively, you might be interested in hiding the dialog, then destroying it once the hide animation finishes.

Here's how you can do it on Dojo 1.5 and earlier (tested 1.3+):

dlg.connect(dlg._fadeOut, 'onEnd', function() {
    this.destroyRecursive();
});
dlg.hide();

In 1.6, the fadeOut animation is no longer exposed on the instance (granted, it was technically private earlier anyway), but onHide now triggers once the animation ends (whereas before it triggered as soon as it began). Unfortunately a setTimeout is needed to get around an error that occurs due to other code in the branch calling onHide, which assumes that something still exists on the instance which won't after we've destroyed it (see #12436).

dlg.connect(dlg, 'onHide', function() {
    setTimeout(function() { dlg.destroyRecursive(); }, 0);
});
dlg.hide();

See it in action on JSFiddle: http://jsfiddle.net/3MNRu/1/ (See the initial version for the original error in the question)

这篇关于dojo dijit.Dialog破坏底层错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 12:30
查看更多