隐藏 dijit.Dialog 时出现 Dojo 异常
我有一个对话框,里面有一个表单。以下代码只是我想要做的事情的一个示例。当你关闭 dijit.Dialog 时,如果你不递归地销毁他的孩子,你就无法重新打开它(使用相同的 id)。
如果您不想销毁您的小部件,您可以执行类似的操作:
var createDialog = function(){
try{
// try to show the hidden dialog
var dlg = dijit.byId('yourDialogId');
dlg.show();
} catch (err) {
// create the dialog
var btnClose = new dijit.form.Button({
label:'Close',
onClick: function(){
dialog.hide();
}
}, document.createElement("button"));
var dialog = new dijit.Dialog({
id:'yourDialogId',
title:'yourTitle',
content:btnClose
});
dialog.show();
}
}
我希望这可以有所帮助,但是使用此代码抛出的错误是:
exception in animation handler for: onEnd (_base/fx.js:153)
Type Error: Cannot call method 'callback' of undefined (_base/fx.js:154)
我不得不说我对这个有点迷失了!这让我发疯^^
PS:对不起我的“法语”英语^^
I have a Dialog with a form inside. The following code is just an example of what I'm trying to do. When you close a dijit.Dialog, if you dont't destroy recursively his children, you just can't reopen it (with the same id).
If you don't want to destroy your widget you can do something like that :
var createDialog = function(){
try{
// try to show the hidden dialog
var dlg = dijit.byId('yourDialogId');
dlg.show();
} catch (err) {
// create the dialog
var btnClose = new dijit.form.Button({
label:'Close',
onClick: function(){
dialog.hide();
}
}, document.createElement("button"));
var dialog = new dijit.Dialog({
id:'yourDialogId',
title:'yourTitle',
content:btnClose
});
dialog.show();
}
}
I hope this can help but with this code the error thrown is :
exception in animation handler for: onEnd (_base/fx.js:153)
Type Error: Cannot call method 'callback' of undefined (_base/fx.js:154)
I have to say I'm a little lost with this one ! It is driving me crazy ^^
PS : sorry for my "French" English ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将向您介绍您的新好朋友:
dojo.hitch()
这允许您将
onClick
函数绑定到创建它的上下文。有可能,当您按下代码中的按钮时,它会在全局窗口的上下文中调用.show()
.hide()
。var dlg
已绑定到您的createDialog
函数,因此它的内部对全局窗口不可见,因此全局窗口将其视为未定义
。以下是我对代码进行的更改的示例:
请注意使用
dojo.hitch()
将各种按钮的任何未来调用或单击绑定到dlg
所在的上下文code> 被创建,永远授予按钮的onclick
方法访问createDialog
函数内部的权限,其中var dlg
存在。I'll introduce you to your new best friend:
dojo.hitch()
This allows you to bind your
onClick
function to the context in which it was created. Chances are, when you push the button in your code, it is calling your.show()
.hide()
form the context of the global window.var dlg
was bound to yourcreateDialog
function, so it's insides are not visible to the global window, so the global window sees this asundefined
.Here's an example of what I changed to your code:
Note the use of
dojo.hitch()
to bind any future calls or clicks of the various buttons to the context in which thedlg
was created, forever granting the button'sonclick
method access to the inside of thecreateDialog
function, wherevar dlg
exists.嗨,如果我理解正确的话,你不需要每次都销毁 dijit.Dialog 。例如:
HTML:定义简单按钮:
Javascript:
参见 示例 并了解 dijit.dialog
hi if i understand correctly, you didn't need to destroy dijit.Dialog every time. E.g.:
HTML: define simple button:
Javascript:
See Example and reed about dijit.dialog