// Load the dom module
require(["dojo/dom"], function(dom){
});
Run Code Online (Sandbox Code Playgroud)
我知道在加载dom模块时会调用该函数,但我不清楚函数中的代码是什么.它是我页面上所有JavaScript代码的容器吗?
该函数是回调函数,AMD加载程序在加载了您需要的所有模块时将调用它.
如果我有
require(["dojo/_base/ready", "dojo/_base/declare"], function(ready, declare) {
// do something with declare and ready
});
Run Code Online (Sandbox Code Playgroud)
AMD将准备加载并声明.这可能需要AMD对服务器进行异步调用.一旦AMD加载了模块,它就会调用您传递给require方法的函数.
我在Dojo Builds的答案......?现在怎么办?有关于AMD API的更多详细信息.
回答评论中的问题.以下两个语句可以在页面的任何位置.
<script type="text/javascript">
require(["dojo/_base/ready", "dojo/_base/declare"], function(ready, declare) {
// do something with declare and ready
});
</script>
<script type="text/javascript">
require(["dojo/_base/ready", "dojo/_base/declare", "dijit/form/Button"],
function(ready, declare, Button) {
// Assuming this is the second statement to be executed, AMD will
// realize that ready and declare have previously been loaded,
// so it will use the previously loaded modules, load the Button module,
// and then execute the callback
// do something with declare, ready, and Button
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2337 次 |
| 最近记录: |