最近开始学习arcgis for javascript,其中dojo是必须学习的框架,今天对相关模块化和对象化进行了研究。
<script >
var dojoConfig = { baseUrl: "itfanr/",packages: [{name:"test",location:"test"}]};
var dojoConfig = { baseUrl: "itfanr/",packages: [{name:"test",location:"test"}]};
目录(dojo中成为路径起点) 下级目录(dojo中成为包)
</script>
</script>
2.有了目录后,在调研文件的时候,从目录下第二级算起,如:dojo/dojo/ready.js 使用require()调用的时候,要这样写require(["dojo/ready"]),需要去掉一个dojo.
实例:person.js放到itfanr/test下,
define(["dojo/_base/declare"],function (declare) {
return declare("person",null,{
name: "zhangsan",
constructor: function (name) {
this.name = name;
},
say: function () {
return this.name;
}
});
});
return declare("person",null,{
name: "zhangsan",
constructor: function (name) {
this.name = name;
},
say: function () {
return this.name;
}
});
});
HtmlPage.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script > var dojoConfig = { baseUrl: "itfanr/",location:"test"}]}; </script> <script src="dojo/dojo/dojo.js"></script> <script > require( ["dojo/ready","test/person"],//这里是从二级目录算起,感觉很别扭 function (ready,person) { ready(function () { var id = "selected_text"; var person1 = new person("dfdsfd"); alert(person1.name); }); }); </script> </head> <body> <h1 id="selected_text">Hello</h1> </body> </html>