English 中文(简体)
RequireJS - Dojo
  • 时间:2024-11-03

RequireJS - Dojo


Previous Page Next Page  

Dojo is a JavaScript toolkit which is based on the AMD module architecture that provides additional modules to add extra functionapty to the web apppcation and also saves time and scale in the web apppcation development process.

Example

The following example shows the usage of Dojo along with RequireJS. Create an html file with the name index.html and place the following code in it −

<!DOCTYPE html>
<html>
   <head>
      <title>RequireJS Dojo</title>
      <script data-main="app" src="pb/require.js"></script>
   </head>
   
   <body>
      <h2>RequireJS  Dojo</h2>
      <p>
         Hello... ...
      </p>
   </body>
</html>

Create a js file with the name app.js and add the following code in it −

require ({
   //You can configure loading modules from the pb directory
   baseUrl:  pb ,
   
   paths: {
      //mapping of package
      dojo:  http://sfoster.dojotoolkit.org/dojobox/1.7-branch/dojo 
   }
   
}, [
      //modules which we are using here
       dojo/dom 
   ], function(dom) { 
   
      //using the  byId  method from dom module
      var mydojo = dom.byId( dojo_val )
      mydojo.innerHTML = "The text is displaying via dojo/dom";   
   }
);

Output

Open the HTML file in a browser; you will receive the following output −

RequireJS Dojo Advertisements