admin管理员组文章数量:1391964
I followed the dojo tutorial to show a "Terms and Conditions" dialog. The dojo version is 1.7.0. I tested the example in chrome. In my test page I right click to show a menu then select item "Inspect Element". I found an error message in tab console. The error message is:
Uncaught TypeError: Cannot call method 'show' of undefined
showDialogdialog
(anonymous function)
onclickdialog
Then I go to the dojo api page. I find dojo 1.7.0 no any methods under the class dijit.Dialog
. So how to show dialog use dojo 1.7.0? Any idea? Thank you so much.
I followed the dojo tutorial to show a "Terms and Conditions" dialog. The dojo version is 1.7.0. I tested the example in chrome. In my test page I right click to show a menu then select item "Inspect Element". I found an error message in tab console. The error message is:
Uncaught TypeError: Cannot call method 'show' of undefined
showDialogdialog
(anonymous function)
onclickdialog
Then I go to the dojo api page. I find dojo 1.7.0 no any methods under the class dijit.Dialog
. So how to show dialog use dojo 1.7.0? Any idea? Thank you so much.
3 Answers
Reset to default 4It seems to be a problem with Google CDN, because the tutorial example works fine with the local copy of Dojo 1.7.
Dojo loader loads the file Dialog.js, but cannot parse it, which results in "parser.js: 8 Uncaught Error: Could not load class 'dijit.Dialog'".
dijit.Dialog.show() method is missing because the Dialog widget is not instanced and dijit.byId("terms") returns "undefined".
To workaround this load dijit.Dialog class/file via script tag:
<script src="http://ajax.googleapis./ajax/libs/dojo/1.7.0/dijit/Dialog.js"></script>
I filled this issue into Dojo bug tracker: Ticket #14415.
From the error message, the dialog object is undefined
. You still use show
function to display a dijit.Dialog
. Double check whether the dijit.Dialog
instance is created successfully.
Sample code:
var dlg = new dijit.Dialog({
id: "myDialog",
title: "Sample",
content: "<div>Hello World!</div>"
});
dlg.show();
The reason that you can not see the show
function in the api doc is because this show
function is actually declared in a internal class dijit._DialogBase
.
I have try dojo 1.7.1 and it's work with this code http://jsfiddle/nv4YC/ dojo 1.7.0 work too.
From your link (the dojo tutorial) it's have to change
dojo.require("dijit.Dialog");
and at the script tag should have async: true
like this data-dojo-config="async: true, parseOnLoad:true"
Let's see on my jsfiddle or try this code
<head>
<link rel="stylesheet" href="http://ajax.googleapis./ajax/libs/dojo/1.6/dijit/themes/claro/claro.css">
<script src="http://ajax.googleapis./ajax/libs/dojo/1.7.1/dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad:true"></script>
<script>
require(["dijit/registry", "dijit/Dialog"], function (registry)
{
// Show the dialog
showDialog = function showDialog()
{
registry.byId("terms").show();
}
// Hide the dialog
hideDialog = function hideDialog()
{
registry.byId("terms").hide();
}
});
</script>
</head>
<body class="claro">
<button onclick="showDialog();">View Terms and Conditions</button>
<div class="dijitHidden">
<div data-dojo-type="dijit.Dialog" style="width:600px;" data-dojo-props="title:'Terms and Conditions'"
id="terms">
<p>
<strong>Please agree to the following terms and conditions:</strong>
</p>
<div style="height:160px;overflow-y:scroll;border:1px solid #769dc4;padding:0 10px;width:600px">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed suscipit
massa. Aenean vel turpis tincidunt velit gravida venenatis. In iaculis
urna non quam tincidunt elementum. Nunc pellentesque aliquam dui, ac facilisis
massa sollicitudin et. Donec tincidunt vulputate ultrices. Duis eu risus
ut ipsum auctor scelerisque non quis ante. Nam tempor lobortis justo, et
rhoncus mauris cursus et. Mauris auctor congue lectus auctor ultrices.
Aenean quis feugiat purus. Cras ornare vehicula tempus. Nunc placerat,
lorem adipiscing condimentum sagittis, augue velit ornare odio, eget semper
risus est et erat....</p>
</div>
<button onclick="hideDialog();">I Agree</button>
<button onclick="alert('You must agree!');">I Don't Agree</button>
</div>
</div>
</body>
本文标签: javascriptWhy dojo 17 can39t show dialogStack Overflow
版权声明:本文标题:javascript - Why dojo 1.7 can't show dialog? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744672371a2618900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论