Here is my code in View
<select data-bind="options:TypeInfo,optionsText: 'PrefName',
optionsValue: 'PrefName',value: $data.selectedchoice,event:
{change:gettrivialtable}" class="forms-dropdown"></select>
Here is my Js Code
viewModel = ko.mapping.fromJS(viewData);
self.TypeInfo = viewModel.TypeInfo;
self.selectedchoice = ko.observable('');
Note : viewData is a Json Pushed from model.PrefName
is a property of the TypeInfo
class. The value returned are 0:'x',1:'y',2:'select'
in the same order I want 'select'
to be the default value. Please help me out.
Here is my code in View
<select data-bind="options:TypeInfo,optionsText: 'PrefName',
optionsValue: 'PrefName',value: $data.selectedchoice,event:
{change:gettrivialtable}" class="forms-dropdown"></select>
Here is my Js Code
viewModel = ko.mapping.fromJS(viewData);
self.TypeInfo = viewModel.TypeInfo;
self.selectedchoice = ko.observable('');
Note : viewData is a Json Pushed from model.PrefName
is a property of the TypeInfo
class. The value returned are 0:'x',1:'y',2:'select'
in the same order I want 'select'
to be the default value. Please help me out.
- Please post your gettrivialtable function – Jacques Snyman Commented May 27, 2013 at 4:58
2 Answers
Reset to default 4you could set your selectedchoice with variable from TypeInfo like:
self.selectedchoice(self.TypeInfo()[0])
or very similar
If you define your self.selectedChoice observable as
self.selectedchoice = ko.observable('select');
the select list will default to that option.