Dojo-Getting Started 篇 Hello Dojo!

I have always wanted to try dojo, after all, it is a “jewel” in the eyes of many JavaScript masters. This article is the first in the dojo series. It will introduce the construction of dojo and the writing of two simple hello word programs.

download dojo

When the network is open, you can use dojo in the simplest way, as follows:

  Tutorial: Hello Dojo! 

Hello

In this way, dojo-related js files will be downloaded from the cdn. Another way is to download the dojo js file and use dojo directly locally.

Download address: http://dojotoolkit.org/download/


Download After decompression, the directory structure is as follows:

< /p>

write dojo helloworld program in Eclipse h

Create a java web project in Eclipse, and then copy dijit/dojo/dojox in dojo to the project.

Ok, now you can write dojo programs. Two simple examples will be written below, one is a simple hello world program, and the other is to use the animation module of dojo to write an example of text sliding.

First example: hello-domReady.html

  Tutorial: Hello Dojo! 

Hello

< !-- load Dojo -->

DOJO is used in the form of asynchronous emodule definition (AMD)). After successfully running the above code, the effect is as follows:


Second example hello-fx.html

  < title>Tutorial: Hello Dojo! 

Hello

After running successfully, "Hello from Dojo!" will automatically shift to the lower right method.

A brief introduction to the hello world program

  • The first parameter of the require method: dojo module id array, each id is a reference to the corresponding module, through which the corresponding api can be called. The module'dojo/dom' in the above example actually corresponds to the dom.js file in the dojo directory.

  • The second of the require method Parameter, callback function: Javascript language uses a callback method to achieve asynchrony. You can use the api of the corresponding module in the callback method.

  • domReady module,When the browser DOM is available, the JavaScript code can be executed, then the domReady module can be used, as in the example above.

Leave a Comment

Your email address will not be published.