Servis-Rhino 4211B Guia do Utilizador Página 139

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 298
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 138
to reveal the content.
Asynchronous Module Definition (AMD)
Dojo package loading is achieved through a technology called "Asynchronous Module Definition"
or AMD. This was first introduced at the Dojo 1.7 release.
In order to use AMD, the Dojo loader must be instructed to execute in async mode:
<script src=".../dojo.js" data-dojo-config="asyc:true"></script>
The loader in this mode exposes only two global functions:
require
define
The require function takes a list of module names to be loaded. Each of these modules is then
loaded which may in turn cause the load of other modules. The second parameter of require()
is a function which will be invoked when all of the modules have been loaded. There will be a
parameter on the function for each module named in the list. The parameter will be mapped to the
reference to the module loaded. These parameters must be supplied in the exact same order as the
corresponding module.
require(["<module>", "<module>", …], function(<var>, <var>, …){...});
All of the modules supplied by Dojo can be accessed this way. We also have the ability to define
our own custom modules.
This is performed through the define() function. Define has the following format:
define(["<module>", "<module>", …], function(<var>, <var>, …)
{
return <value>
});
Now let us talk about module names. A module belongs in a package and has a name. The format
used is the file system style of directory followed by "slash". For example
dijit/layout/TabContainer
myPackage/MyModule
a/b/C
Here is an example of a module definition:
The following is placed in MyModule.js
define([], function () {
return {
"test": function () {
console.log("The darn thing worked!");
}
}
});
Now, let us assume that this is placed in a folder called "myPackage".
In order to use this we can code:
require(["myPackage/MyModule"], function(myModule)
{
myModule.test()
});
Before the package list in the require method, we can also provide a configuration object. This
object has the following properties:
paths
Page 139
Vista de página 138
1 2 ... 134 135 136 137 138 139 140 141 142 143 144 ... 297 298

Comentários a estes Manuais

Sem comentários