隐藏 dijit.Dialog 时出现 Dojo 异常

发布于 2024-10-30 21:58:54 字数 959 浏览 0 评论 0原文

我有一个对话框,里面有一个表单。以下代码只是我想要做的事情的一个示例。当你关闭 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单挑你×的.吻 2024-11-06 21:58:54

我将向您介绍您的新好朋友:dojo.hitch()

这允许您将 onClick 函数绑定到创建它的上下文。有可能,当您按下代码中的按钮时,它会在全局窗口的上下文中调用 .show() .hide()var dlg 已绑定到您的 createDialog 函数,因此它的内部对全局窗口不可见,因此全局窗口将其视为未定义

以下是我对代码进行的更改的示例:

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();
}); 

请注意使用 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 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.

表情可笑 2024-11-06 21:58:54

嗨,如果我理解正确的话,你不需要每次都销毁 dijit.Dialog 。例如:

HTML:定义简单按钮:

<button id="buttonTwo" dojotype="dijit.form.Button" onclick="showDialog();" type="button">
   Show me!
</button>

Javascript:

// required 'namespaces'
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");

// creating dialog
var secondDlg;
dojo.addOnLoad(function () {
        // define dialog content
        var content = new dijit.form.Button({
                    label: 'close',
                    onClick: function () {
                              dijit.byId('formDialog').hide();
                             }
            });

     // create the dialog:
         secondDlg = new dijit.Dialog({
                id: 'formDialog',
                title: "Programatic Dialog Creation",
                style: "width: 300px",
                content: content
            });
        });

          function showDialog() {
            secondDlg.show();
         }

参见 示例 并了解 dijit.dialog

hi if i understand correctly, you didn't need to destroy dijit.Dialog every time. E.g.:

HTML: define simple button:

<button id="buttonTwo" dojotype="dijit.form.Button" onclick="showDialog();" type="button">
   Show me!
</button>

Javascript:

// required 'namespaces'
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");

// creating dialog
var secondDlg;
dojo.addOnLoad(function () {
        // define dialog content
        var content = new dijit.form.Button({
                    label: 'close',
                    onClick: function () {
                              dijit.byId('formDialog').hide();
                             }
            });

     // create the dialog:
         secondDlg = new dijit.Dialog({
                id: 'formDialog',
                title: "Programatic Dialog Creation",
                style: "width: 300px",
                content: content
            });
        });

          function showDialog() {
            secondDlg.show();
         }

See Example and reed about dijit.dialog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文