我有一个旧的ZendApplication(ZF1),现在我尝试将此应用转移到ZF3。在App中,我使用一些Dojo Elements,例如帮助对话框。在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不是构造函数
我的错误在哪里?
编辑:在我看来,我会像这样在锚中调用该函数:'href =“ javascript:showHelp('Help')”> HELP'
EDIT2:我F12调试它,但对话框没有定义,但找到了dijit。
我发现了我的错误。我只更改了Dojo的要求,因此可以正常工作:dojo.require ('dijit.form.Button');
似乎您将1.7之前的dojo样式与1.7 +之前的样式混合在一起(例如,有关[1.7]之前和之后require的用法,请参见here)。因为我看到'async: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!');
});