In a MVC application im generating multiple dropdowns from the database:
<select data-bind="options: findGroup(1).items(),
optionsText: 'country',
optionsValue: 'id',
value: selectedItem(1),
event: { change: selectionChange }"></select>
I need the current selected in my code, but for Debugging puroses im using a span:
<span data-bind="text: 'Computed Selected Country: ' + selectedItem(1).country"></span><br />
the findgroup(x) and the selectedItem(x) are global functions in my ViewModel while those are for all the dropdowns the same.
the selectedItem(x) should return the currently selected Option of the dropdown. selectedItem(x) is a function to return a computed knockout observable. the selectedItem(x) always Returns "undefined", cant figure out why...
full example: http://jsfiddle.net/LGveR/17/
TIA, Paul
Your function returns a computed so it needs to be executed like,
this.selectedItem(1)().country
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments