Widgets appear in more and more web applications. So, what is a widget? What are the markup methods used by widgets to declare them? Can widgets be dynamically created? What are the common methods and attributes of widgets ?...... This series of problems come to our minds. Let's take a look at them.
Learning 1: widget meaning
The English meanings of widgets are decorations or gadgets. Some Technical Documents translate them into widgets and use their English names directly here to avoid unnecessary confusion. The reasons why dojo provides the widget framework are as follows: one is to provide a better user experience, and the other is to help developers develop web applications quickly.
Learning 2: widget Declaration
The dojo widget provides a large number of UI controls that can be directly used. It also supports the declaration of the TAG method. Where,DojotypeIt is a key attribute for declaring a dojo widget. It specifies the widget type. For example:
<ButtonId = "button" dojotype = "button"> Create </button>.
You can also declare a Button widget in the page as follows: <button id = "button"Class="Dojo-button"> Create </button>; or <Dojo: buttonId = "button" caption = "CREATE"/>
Learning 3: dynamically create widgets in Dojo
Dojo supports dynamic creation of widgets, for exampleCodeDynamically create a Button widget and add it to the page:
Create Button widget
W =Dojo. widget. createwidget("Button", {caption: "CREATE "});
Dojo. Body (). appendchild(W. domnode );
Learning 4: common methods and attributes in widget Programming
In dojo, the features of widgets can be changed through programming. The following are common methods and attributes in widget programming.
- Dojo. widget. byid (ID ):Retrieve widget objects by ID
- Dojo. widget. createwidget:Dynamically create widget objects
- Widgetobject. domnode:Dom node corresponding to the widget object
- Widgetobject. containernode: Dom node corresponding to the container where the widget object is located
- Widgetobject. Show ()/hide ():Show/hide Widgets
- Widgetobject. Toggle ():Switch the display/hide status of Widgets
- Widgetobject. isshowing ():Visible Widgets
Learning 5: Types of dojo Widgets
Currently, Dojo provides a wide range of widget libraries to meet the development needs of most web applications. Dojo widgetBy purposeIt can be divided into three categories:
- Used for page layoutLayout widget
- Used for form EnhancementForm widget
- Implement common functionsGeneral Widgets
Summary:
The dojo widget framework has goodScalabilityDevelopers can develop custom widgets to reuse code.