0

New to Dojo and I am just trying to get a basic Hello world module working in dojo/MVC and can't seem to get it to work. I keep getting either

no response / errors at all or cryptic Syntax errors in dojo.js e() h.injectUrl/h()

is what it says when using FireFox / Firebug. I am using 1.8 and have tried both the CDN and local copies.

Here is the code below.

Index.cshtml

    <script src="~/Scripts/dojo/dojo.js" data-dojo-config="async: true, isDebug: true, parseOnLoad: true"></script><script>
    // Require default stuff and new module
    require([
                "~/Scripts/dojoDemo/newModule"
    ],
    function (newModule) {
        newModule.setText("greetings", "Hello peoples");
        settimeout(function () {
            newModule.restoreText("greeting");
        }, 3000);
    });</script><h1 id="greetings">What up</h1>

<br/>
<br/>

newModule.js

define([
    // Define the dependencies
    "dojo/dom"], 
    // Create this function to call new module
    function (dom) {
        var oldText = {};
        return {
            setText: function (id, text) {
                var node = dom.byId(id);
                oldText[id] = node.innerHTML;
                node.innerHTML = text;
            },
            restoreText: function (id) {
                var node = dom.byId(id);
                node.innerHTML = oldText[id];
                delete oldText;
            }
        };
    });
4

1 回答 1

1

You need to specify the path to the module in the dojo config and not the require call. paths map the top level module name to where the files are located to the server. By default, the file path is relative to dojo.js

<script src="~/Scripts/dojo/dojo.js" 
  data-dojo-config="async: true, isDebug: true, parseOnLoad: true, 
     paths: { dojoDemo: '../dojoDemo' }">
</script>
<script>
  require(["dojoDemo/newModule", "dojo/domReady!"], function (newModule) {
      newModule.setText("greeting", "Hello peoples");
      setTimeout(function () {
          newModule.restoreText("greeting");
      }, 3000);
  });
</script>
于 2013-03-01T18:31:13.167 回答