I am running a function that needs to close a Dojo dialog if it is loaded. How do I check if a dojo dialog is running? Do I use pure JavaScript and check by id if it is undefined?
我正在运行一个函数,如果它被加载,需要关闭一个Dojo对话框。如何检查dojo对话框是否正在运行?如果未定义,我是否使用纯JavaScript并按ID检查?
if (dijit.byId("blah") !== undefined) {
destroyRecursive dijit;
}
Or do I use a property of the dialog object like:
或者我使用对话框对象的属性,如:
isFocusable method
isLoaded property
2 个解决方案
#1
Dialog provides two properties you might want to check: isLoaded
and open
. By digging the code you'll find the following descriptions:
Dialog提供了两个您可能想要检查的属性:isLoaded和open。通过挖掘代码,您将找到以下描述:
- open: True if Dialog is currently displayed on screen.
- isLoaded: True if the ContentPane has data in it, either specified during initialization (via href or inline content), or set via attr('content', ...) / attr('href', ...) False if it doesn't have any content, or if ContentPane is still in the process of downloading href.
open:如果屏幕上当前显示Dialog,则为True。
isLoaded:如果ContentPane中包含数据,则为True,在初始化期间指定(通过href或内联内容),或者通过attr('content',...)/ attr('href',...)设置,如果它,则为False没有任何内容,或者ContentPane仍在下载href的过程中。
So, you could just:
所以,你可以:
var dialog = dijit.byId("blah");
if( dialog.open ) {
dialog.destroy();
}
#2
Do you want to hide it or destroy it?
你想隐藏它还是摧毁它?
If you just want to show/hide it you can do the following:
如果您只想显示/隐藏它,您可以执行以下操作:
var dialog = dijit.byId('blah');
if (dialog) {
if (dialog.open) {
dialog.hide();
}
else {
dialog.show();
}
}
If you wanted to destory it to free up memory:
如果你想破坏它以释放内存:
var dialog = dijit.byId('blah');
dialog.destory();
I think destroy
is recursive since it calls its parent destroy
method and one of its parents is dijit.layout.ContentPane
.
我认为destroy是递归的,因为它调用它的父destroy方法,其父节点之一是dijit.layout.ContentPane。
#1
Dialog provides two properties you might want to check: isLoaded
and open
. By digging the code you'll find the following descriptions:
Dialog提供了两个您可能想要检查的属性:isLoaded和open。通过挖掘代码,您将找到以下描述:
- open: True if Dialog is currently displayed on screen.
- isLoaded: True if the ContentPane has data in it, either specified during initialization (via href or inline content), or set via attr('content', ...) / attr('href', ...) False if it doesn't have any content, or if ContentPane is still in the process of downloading href.
open:如果屏幕上当前显示Dialog,则为True。
isLoaded:如果ContentPane中包含数据,则为True,在初始化期间指定(通过href或内联内容),或者通过attr('content',...)/ attr('href',...)设置,如果它,则为False没有任何内容,或者ContentPane仍在下载href的过程中。
So, you could just:
所以,你可以:
var dialog = dijit.byId("blah");
if( dialog.open ) {
dialog.destroy();
}
#2
Do you want to hide it or destroy it?
你想隐藏它还是摧毁它?
If you just want to show/hide it you can do the following:
如果您只想显示/隐藏它,您可以执行以下操作:
var dialog = dijit.byId('blah');
if (dialog) {
if (dialog.open) {
dialog.hide();
}
else {
dialog.show();
}
}
If you wanted to destory it to free up memory:
如果你想破坏它以释放内存:
var dialog = dijit.byId('blah');
dialog.destory();
I think destroy
is recursive since it calls its parent destroy
method and one of its parents is dijit.layout.ContentPane
.
我认为destroy是递归的,因为它调用它的父destroy方法,其父节点之一是dijit.layout.ContentPane。