为了账号安全,请及时绑定邮箱和手机立即绑定

dijit.dialog 不是构造函数

dijit.dialog 不是构造函数

陪伴而非守候 2022-06-09 19:31:14
我有一个旧的 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。
查看完整描述

2 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

似乎您混合了 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){

    ...

    var helpDlg = new Dialog({...});

    helpDlg.show();

});

注意约定是把dojo/domReady! 最后(见这里)。另请注意,不推荐使用 dojo.xhrGet(...)(请参见此处)...这并不意味着它不起作用(我不熟悉 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!');

});


查看完整回答
反对 回复 2022-06-09
?
胡说叔叔

TA贡献1804条经验 获得超8个赞

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



查看完整回答
反对 回复 2022-06-09
  • 2 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号