1. dojo.baseUrl
默认值是dojo的根目录,比如dojo.js的路径是在/web/scripts/dojo-1.3/dojo/dojo.js,那么这个baseUrl就是/web/scripts/dojo-1.3/dojo/ .
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad: true">
</script>
<script type = "text/javascript">
dojo.require("dir.foo");
dojo.addOnLoad(function(){
dojo.body().innerHTML = "fibonacci(5)";
});
</script>
</head>
<body>
</body>
</html>
上面你的文档中,baseUrl就是dojo/ .
2.dojo.require(some.module)
这时候,dojo就会加载/web/scripts/dojo-1.3/some/module.js,注意baseUrl是/web/scripts/dojo-1.3/dojo/哦。
3.一个简单的例子
把dir目录放在和dojo目录同一级别,然后往dir目录中添加如下js文件:dojo.provide("dir.foo");
function fib (x){ if(x < 0) throw Exception("Illegal argument"); if(x <= 1) return x; return fib(x - 1) + fib(x - 2); }
在dojo目录同一级别下,放html文件:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad: true,isDebug:true">
</script>
<script type = "text/javascript">
dojo.require("dir.foo");
dojo.addOnLoad(function(){
dojo.body().innerHTML = fib(5);
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="dojo/dojo.js"
data-dojo-config="async: true, parseOnLoad: true,isDebug:true">
</script>
<script type = "text/javascript">
dojo.registerModulePath("dir","../dir");//baseUrl是dojo/, 模块路径是相对baseUrl来的
dojo.require("dir.foo");
dojo.addOnLoad(function(){
dojo.body().innerHTML = fib(5);
});
</script>
</head>
<body>
</body>
</html>