重命名核心 Dojo 包

发布于 2025-01-07 08:06:07 字数 1678 浏览 0 评论 0原文

当使用 Dojo 1.6 时,我可以像这样“重命名”核心 dojo 包:

<html>

<head>

<script type="text/javascript">
   djConfig = {
      baseUrl: 'https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/',
      scopeMap: [
         [ 'dojo', 'myDojo' ]
      ]
   }
</script>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>
</head>

<body>
<script type="text/javascript">
   if (typeof dojo != 'undefined') {
      document.write("Defined: dojo: " + dojo.version + '\n');
   }
   if (typeof myDojo != 'undefined') {
      document.write("Defined: myDojo: " + myDojo.version + '\n');
   }
</script>
</body>

</html>

上面打印“Defined: myDojo: 1.6.1...”。我如何在 Dojo 1.7 中完成同样的事情?按照这里的示例,我尝试了这个测试,无济于事:

<html>

<head>

<script type="text/javascript">
   dojoConfig = {
      baseUrl: 'dojo/1.7.2/dojo/',
      packages: [
         { name: 'myDojo',
           location: '../dojo',
           packageMap: {
              dojo: 'myDojo'
           }
         }
      ]
   }
</script>
<script src="dojo/1.7.2/dojo/dojo.js"></script>
</head>

<body>
<script type="text/javascript">
   if (typeof dojo != "undefined") {
      document.write("Defined: dojo: " + dojo.version + '\n');
   }
   if (typeof myDojo != "undefined") {
      document.write("Defined: myDojo: " + myDojo.version + '\n');
   }
</script>
</body>

</html>

这会打印“已定义:dojo:1.7.2 ...”。我缺少什么?

When using Dojo 1.6, I can "rename" the core dojo package like so:

<html>

<head>

<script type="text/javascript">
   djConfig = {
      baseUrl: 'https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/',
      scopeMap: [
         [ 'dojo', 'myDojo' ]
      ]
   }
</script>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>
</head>

<body>
<script type="text/javascript">
   if (typeof dojo != 'undefined') {
      document.write("Defined: dojo: " + dojo.version + '\n');
   }
   if (typeof myDojo != 'undefined') {
      document.write("Defined: myDojo: " + myDojo.version + '\n');
   }
</script>
</body>

</html>

The above prints "Defined: myDojo: 1.6.1...". How can I accomplish the same thing in Dojo 1.7? Following the example here, I tried this test, to no avail:

<html>

<head>

<script type="text/javascript">
   dojoConfig = {
      baseUrl: 'dojo/1.7.2/dojo/',
      packages: [
         { name: 'myDojo',
           location: '../dojo',
           packageMap: {
              dojo: 'myDojo'
           }
         }
      ]
   }
</script>
<script src="dojo/1.7.2/dojo/dojo.js"></script>
</head>

<body>
<script type="text/javascript">
   if (typeof dojo != "undefined") {
      document.write("Defined: dojo: " + dojo.version + '\n');
   }
   if (typeof myDojo != "undefined") {
      document.write("Defined: myDojo: " + myDojo.version + '\n');
   }
</script>
</body>

</html>

This prints "Defined: dojo: 1.7.2...". What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

死开点丶别碍眼 2025-01-14 08:06:07

要在使用源版本时使全局变量重新映射起作用,您需要将 dojoConfig.async 设置为 true,然后需要加载 'myDojo' 包。

http://jsfiddle.net/neonstalwart/44e56/ 是以下代码的工作示例:

<script type="text/javascript">
    // configure dojo
    dojoConfig = {
        async: 1,
        packages: [
            {
                name: 'myDojo',
                location: '../1.7.2',
                // re-map globals to different names
                packageMap: {
                    dojo: 'myDojo'
                }
            }
        ],
        deps: ['myDojo'],
        callback: function () {
            if (typeof dojo != "undefined") {
                alert("Defined: dojo: " + dojo.version + '\n');
            }
            if (typeof myDojo != "undefined") {
                alert("Defined: myDojo: " + myDojo.version + '\n');
            }
        }
    };
</script>
<script type="text/javascript" src="https://raw.github.com/dojo/dojo/1.7.2/dojo.js"></script>

to get the remapping of globals to work when using the source version, you need to set dojoConfig.async to something truthy and then you need to load the 'myDojo' package.

http://jsfiddle.net/neonstalwart/44e56/ is a working example of the code below:

<script type="text/javascript">
    // configure dojo
    dojoConfig = {
        async: 1,
        packages: [
            {
                name: 'myDojo',
                location: '../1.7.2',
                // re-map globals to different names
                packageMap: {
                    dojo: 'myDojo'
                }
            }
        ],
        deps: ['myDojo'],
        callback: function () {
            if (typeof dojo != "undefined") {
                alert("Defined: dojo: " + dojo.version + '\n');
            }
            if (typeof myDojo != "undefined") {
                alert("Defined: myDojo: " + myDojo.version + '\n');
            }
        }
    };
</script>
<script type="text/javascript" src="https://raw.github.com/dojo/dojo/1.7.2/dojo.js"></script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文