dropdown list in konckout is empty

29 views
Skip to first unread message

nader....@telia.com

unread,
Apr 25, 2015, 6:00:45 PM4/25/15
to knock...@googlegroups.com
I have the follwing knockout code but the resulting dropdownlist in html page dose not show anything.

<script type='text/javascript' src='knockout-3.3.0.js'></script>

<p>
Behandlingsmetod: 
<select data-bind="options: behandlingsmetod, value: selectedbehandling,
              optionstext:'selectedbehandling',
                       optionsCaption: 'Choose...'" size="5" multiple="true"></select>   
 </p>

<script>
function BehandlingViewModel()
{
  var self = this;
   self.förnamn = ko.observable();
   self.lastName = ko.observable();
   self.personnummer = ko.observable();
   self.behandlingsmetod =  ko.observableArray(['first', 'second', 'third']);
   self.selectedbehandling = ko.observable();
    
};
ko.applyBindings(new BehandlingViewModel());
</script>

bmey...@gmail.com

unread,
Apr 25, 2015, 9:44:46 PM4/25/15
to knock...@googlegroups.com, nader....@telia.com
The options binding will bind each object in the array. the other parameters such as optionstext: 'selectedbehandling' are treated as properties on the object.

if you removed, the optionstext and value, things will start working.

here is a jsfiddle link with a basic working.


Brandon
Reply all
Reply to author
Forward
0 new messages