Newbie Dojo - Google CDN Question

心不动则不痛 提交于 2019-12-13 03:32:49

问题


I have a test jsp with:

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript">
</script>

<script type="text/javascript"> 
dojo.require("dojo.widget.Tree"); 
dojo.require("dojo.widget.TreeSelector"); 
dojo.require("dojo.widget.TreeNode"); 
dojo.require("dojo.widget.TreeContextMenu"); 
</script> 
</head>

<body>
<div dojoType="TreeSelector" widgetId="treeSelector"></div> 
<div dojoType="Tree" widgetId="treeWidget" selector="treeSelector"toggler="wipe"> 
<div dojoType="TreeNode" widgetId="1" title="First node" isFolder="false"></div> 
<div dojoType="TreeNode" widgetId="2" title="Second node"> 
    <div dojoType="TreeNode" widgetId="2.1" title="Second node First Child"></div> 
    <div dojoType="TreeNode" widgetId="2.2" title="Second node Second Child"></div> 
</div> 
<div dojoType="TreeNode" widgetId="3" title="Third node" isFolder="false"></div> 
</div>

This will not work in any browser. I thought this would be easy, it seems the dojo library is not being downloaded/found? Do I need to do anything else?

Also, my IDE, JDeveloper, reports that the attribute "dojoType" is not defined on element div.


回答1:


I have to say, this example looks like it is taken from a very old version of dojo, but you're trying to run it against Dojo 1.5. That most likely won't work. dojo.widget hasn't existed since...0.4, 0.9 maybe.

You may be right in your comment to the previous answer in that no parseOnLoad: true was necessary in the original example, but I'd also assure you that that example was not running any version of Dojo anywhere near what you're running it with.

Based on what you're looking at there, you may want to start somewhere like here: http://www.dojotoolkit.org/reference-guide/dijit/Tree.html




回答2:


I'm not sure what the default behavior is when it's not present, but you probably need to define a djConfig with parseOnLoad set to true (or call the parser directly). See the following links for more information:

http://docs.dojocampus.org/djConfig

http://dojocampus.org/content/2008/03/08/the-dojo-parser/




回答3:


Follow the:

  • Google AJAX Libraries API Dev Guide,
  • and the Google API Loader's Guide.

You need to:

  • register for an API key (or use a direct link as you did),
  • if not using a direct link but google.load, you need to defer the execution of your code using an onload callback.

Personally, I would just do something like:

within the <head> section of my.html:

<script type="text/javascript" src="http://www.google.com/jsapi?key=MY_API_KEY_GOES_HERE"></script>
<script type="text/javascript" src="my.js"></script>

in my.js:

google.load("dojo", "1.5", {
  uncompressed: true
});

function OnLoad() {
  /* do stuff here */
}

google.setOnLoadCallback(OnLoad);


来源:https://stackoverflow.com/questions/3945147/newbie-dojo-google-cdn-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!