重命名核心 Dojo 包
当使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在使用源版本时使全局变量重新映射起作用,您需要将
dojoConfig.async
设置为 true,然后需要加载'myDojo'
包。http://jsfiddle.net/neonstalwart/44e56/ 是以下代码的工作示例:
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: