dojo dijit.dialog不是构造函数

wgeznvg7  于 2022-12-16  发布在  Dojo
关注(0)|答案(2)|浏览(126)

我有一个旧的ZendApplication(ZF1),现在我尝试将此应用程序转移到ZF3。在应用程序中,我使用了一些Dojo元素,例如Helpdialog。在ZF3中,Dojo不直接受Zend支持,因此我使用Dojo direct而不使用Zend Interaction。
因此,在我的布局视图中,我像这样加载Dojo:

<script src="<?= $this->basePath()?>/assets/custom/js/dojo/dojo/dojo.js" data-dojo-config="async: true,isDebug: true,parseOnLoad: true">

require ([
    'dijit/Dialog',
    'dijit/form/Button',
    'dijit/form/SimpleTextarea',
....
  'dojox/widget/Standby',
  'dojo/domReady!',
],)
);

这是我想要使用的代码:

require (['dojo/domReady!','dijit/Dialog']);
          function showHelp(id,help) {
                dojo.xhrGet({
                    url: "http://localhost/NeuesProjekt/public/test/test",
                    //url:"http://localhost/NeuesProjekt/public/", // baseUrl + "/help/index/charkey/" + id,
                    load: function(data) {
                            helpDlg = new dijit.Dialog({
                                title: "help",
                                content: "data",
                                style: "width: 550px;"
                            });
                            helpDlg.show();
                    },
                    error: function(error) {
                            var data = "An unexpected error occurred: " + error;
                            helpDlg = new dijit.Dialog({
                                title: "help",
                                content: "data2",
                                style: "width: 550px"
                            });
                            helpDlg.show();
                    }
                });

            };

它将工作,直到应用程序来到new dijit.Dialog那里,我得到了错误 *dijit.对话框不是一个构造函数 *
我错在哪里?
编辑:在我的观点中,我调用了锚中的函数,如下所示:' href=“javascript:显示帮助('帮助')"〉帮助'
EDIT2:如果F12调试告诉我未定义对话框,但找到了dijit。

axzmvihb

axzmvihb1#

看起来你混合了1.7之前的dojo风格和1.7 +的dojo风格(例如,请参见here,了解1.7之前和之后require的用法)。true ',您正在使用的版本od dojo〉= 1.7。请参阅here如何正确使用dojo AMD加载器。您使用require语句的方式,您不确定当您使用它们时,相应的模块是否会被加载(它是异步的)。这可能是您在new dijit. dialog上得到错误的原因。正确的方式是:

require ([dijit/Dialog, dojo/domReady!], function(Dialog){
    ...
    var helpDlg = new Dialog({...});
    helpDlg.show();
});

注意,惯例是把dojo/domReady!放在最后(参见here)。还要注意dojo.xhrGet(...)被弃用(参见here)...这并不意味着它不能工作(我不熟悉1.7之前的风格)。
编辑回答您的意见如下:

require ([dijit/Dialog, dojo/domReady!], function(Dialog){
    var showHelp = function(id, help){
        ...
        var helpDlg = new Dialog({...});
        ...
        helpDlg.show();
        ...
    }
    showHelp(1, 'please help me!');
});
e4eetjau

e4eetjau2#

我发现了我的错误。我只改变了Dojo的需求,所以它会工作:dojo.require ('dijit.form.Button');

相关问题