0
votes

I am binding select list in knockout

Html:

<select data-bind="options: $parent.Languages, optionsValue:function(item) { return item.Value; }, optionsText: function(item) {return item.Text; }, value: LanguageID, valueUpdate: 'change'" />

on submit ==> var data = ko.mapping.toJS(viewModel1);

Controller:

Languages = new SelectList(this.Languages(), "ID", "LanguageName", SelectedLanguageID);

It returns the complete object in LanguageID = "Selected: true, ID: 1, LanguageName: "English" but i want that it should return only ID like LanguageID = 1

I already use subscribe method and assign

1

1 Answers

5
votes

A few things:

  • Make sure that you properly open/close your select like: <select></select>

  • You can simplify your optionsText and optionsValue specifications by just passing the property name that you want as a string (<select data-bind="options: Languages, optionsValue: 'Value', optionsText: 'Text', value: LanguageID" ></select>)

  • You do not need to use valueUpdate on a select

Otherwise, it seems to be working properly.

Here is a sample: http://jsfiddle.net/rniemeyer/dgmV6/