Lists
dijit/form/MultiSelect
The MultiSelect widget allows the user to select from a set of available options shown on a list.
It can be used to select a single item or multiple items. It is basically a wrapper around the HTML
<select> element.
To programatically add an entry into the widget, use the following:
domConstruct.create("option", {
innerHTML: "<label>",
value: "<value>"
},selectWidget.domNode);
To set the vertical size of the widget as a number of elements to show, set the "size" attribute.
To provide single selection set the "multiple" attribute to false.
An event on the widget called "change" is invoked when the selection changes. The data passed
into the event is an array of the values (the value property of the option element) of the selected
item(s). Even is single select is in effect, an array is still passed but will just contain the single
selected item.
If we wish to delete all the entries in the list, the following will work:
query("option", multiSelectWidget.domNode).orphan("*");
<select dojoType="dijit/form/MultiSelect" id="MultiSelect" style="width: 100px">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
dijit/form/Select
The select widget shows a simple selection pull-down.
The AMD package for this widget is "dijit/form/Select" and is commonly bound to
"Select".
Options can be programatically added via the "addOption()" method. This can take a single
option object or an array of option objects. An option object is a JavaScript object with two
properties:
• label – The label to show in the list. This should be a string.
• value – The value of the entry in the list. This should also be a string.
From a declarative perspective, we can use the following HTML:
<select name="select1" data-dojo-type="dijit/form/Select">
<option value="TN">Tennessee</option>
<option value="VA" selected="selected">Virginia</option>
<option value="WA">Washington</option>
<option value="FL">Florida</option>
Page 157
Comentários a estes Manuais