猿问

dijit.dialog 不是构造函数

我有一个旧的 ZendApplication (ZF1),现在我尝试将此应用程序转移到 ZF3。在应用程序中,我使用了一些 Dojo 元素,例如 Helpdialog。在 ZF3 中,Zend 不直接支持 Dojo,所以我直接使用 Dojo,而没有 Zend 交互。


因此,在我的布局视图中,我像这样加载 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.dialog is not a constructor


我的错误在哪里?


编辑:在我看来,我在这样的锚点中调用函数:' href="javascript:showHelp('Help')">HELP'


EDIT2:我 F12 调试它告诉我没有定义对话框,但找到了 dijit。


陪伴而非守候
浏览 188回答 2
2回答

jeck猫

似乎您混合了 1.7 之前的 dojo 样式和 1.7 + one(请参阅此处以了解在 1.7 之前和之后使用 require 的示例)。因为我看到'async: true',所以您使用的是 od dojo > = 1.7 版本。请参阅此处如何正确使用 dojo AMD 加载程序。你使用 require 语句的方式,你不确定使用它们时是否会加载相应的模块(它是异步的)。这可能是您在新 dijit.dialog 上收到错误的原因。正确的方法是:require ([dijit/Dialog, dojo/domReady!], function(Dialog){&nbsp; &nbsp; ...&nbsp; &nbsp; var helpDlg = new Dialog({...});&nbsp; &nbsp; helpDlg.show();});注意约定是把dojo/domReady! 最后(见这里)。另请注意,不推荐使用 dojo.xhrGet(...)(请参见此处)...这并不意味着它不起作用(我不熟悉 1.7 之前的样式)。编辑以在下面回答您的评论:require ([dijit/Dialog, dojo/domReady!], function(Dialog){&nbsp; &nbsp; var showHelp = function(id, help){&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; var helpDlg = new Dialog({...});&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; helpDlg.show();&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; }&nbsp; &nbsp; showHelp(1, 'please help me!');});

胡说叔叔

我发现了我的错误。我只更改了 Dojo 的要求,所以它会起作用:&nbsp;dojo.require ('dijit.form.Button');
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答