knockout.js - Bind a <select> to an array in knockoutjs? -


i have checkbox list on page bound knockout observablearray.

when checkboxes selected knockout updates observablearray expected [123, 345, 456] (if 3 options in checkbox list selected)

it fires off few functions goes through array , bunch of things.

my trouble want able switch between using checkbox list , <select>. single select vs multiselect, using same ko.observable...

these functions don't work when it's flat string , not array.

when using <select>, there way can observable function single value array?

e.g using select...

<select data-bind="value: myobservable"> 

i want make selected value in myobservable be:

["123"] (or [123]) 

instead of plain string

"123" 

you can use selectedoptions binding instead of value.

<select data-bind="selectedoptions: myobservable"> 

if need multiple selection can use multiple="true":

jsfiddle


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -