select multiple
2.1
can.view.bindings.can-value-select-multiple
Cross bind a value to a <select>
element with multiple selections permitted.
<select multiple can-value='KEY'/>
Cross binds the selected option values with an observable value.
Parameters
-
KEY
{key}
A named value in the current scope.
KEY
's value is cross bound with the selected<option>
in the<select>
.KEY
's value should be either Array-like, a String, orundefined
.
Use
Select elements with the multiple attribute (
<select multiple can-value="KEY"/>
) have a specified behavior if the value of KEY is Array like, a String, or undefined.Cross binding to Arrays
<select>
tags with a multiple attribute cross bind a can.Map property, can.compute or can.List in sync with the selected items of the<select>
element.For example, the following template:
Could be rendered with one of the following:
Cross binding Strings
If the can.Map property or can.compute value is a string like:
The string will be split by
";"
. The items in the split string are used as values to match against<option>
tag values.Cross binding undefined
If the
KEY
value begins as undefined can.Map property like:The property will be converted to a can.List.
If the
KEY
value begins as an undefined can.compute like:The value of the compute will be set to an array.