Dojo异常隐藏dijit.Dialog [英] Dojo Exception on hiding a dijit.Dialog
问题描述
如果你不想破坏你的小部件你可以这样做:
var createDialog = function(){
try {
//尝试显示隐藏对话框
var dlg = dijit.byId('yourDialogId');
dlg.show();
} catch(err){
//创建对话框
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();
}
}
我希望这可以帮助,但是使用这段代码抛出的是:
动画处理程序中的异常:onEnd(_base / fx.js:153)
类型错误:无法调用未定义的方法回调(_base / fx.js:154)
我不得不说我有点迷失了这个!这是驱使我疯狂^^
PS:抱歉为我的法语英语^^
我会向你介绍你最好的朋友: dojo.hitch()
这允许您将 onClick
函数绑定到创建它的上下文。有可能的是,当您按下代码中的按钮时,它正在调用您的 .show()
.hide()
形成全局窗口的上下文。 var dlg
绑定到你的 createDialog
函数,所以它的内部对于全局窗口是不可见的,所以全局窗口看到这个是 undefined
。
以下是我更改代码的示例:
var createDialog = function(){
//尝试显示隐藏对话框
var dlg = dijit。 byId( 'yourDialogId');
dlg.show();
//创建对话框
var btnClose = new dijit.form.Button({
label:'Close',
onClick:function(){
dojo.hitch(this,dlg.hide());
}
},document.createElement(button));
dlg.domNode.appendChild(btnClose.domNode);
var btnShow = new dijit.form.Button({
label:'Open',
onClick:function(){
dojo.hitch(this,dlg.show() );
}
},document.createElement(Button));
dojo.body()。appendChild(btnShow.domNode);
};
dojo.ready(function(){
createDialog();
});
请注意使用 dojo.hitch()
将任何将来的各种按钮的调用或点击绑定到创建 dlg
的上下文中,永远授予按钮的 onclick
方法访问 createDialog
函数的内部,其中 var dlg
存在。
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 ^^
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 your createDialog
function, so it's insides are not visible to the global window, so the global window sees this as undefined
.
Here's an example of what I changed to your code:
var createDialog = function(){
// try to show the hidden dialog
var dlg = dijit.byId('yourDialogId');
dlg.show();
// create the dialog
var btnClose = new dijit.form.Button({
label:'Close',
onClick: function(){
dojo.hitch(this, dlg.hide());
}
}, document.createElement("button"));
dlg.domNode.appendChild(btnClose.domNode);
var btnShow = new dijit.form.Button({
label : 'Open',
onClick : function() {
dojo.hitch(this, dlg.show());
}
}, document.createElement("Button"));
dojo.body().appendChild(btnShow.domNode);
};
dojo.ready(function() {
createDialog();
});
Note the use of dojo.hitch()
to bind any future calls or clicks of the various buttons to the context in which the dlg
was created, forever granting the button's onclick
method access to the inside of the createDialog
function, where var dlg
exists.
这篇关于Dojo异常隐藏dijit.Dialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!