Paul
Paul

Reputation: 165

Knockout Computed with Parameter not updated

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

Upvotes: 1

Views: 79

Answers (1)

Anders
Anders

Reputation: 17554

Your function returns a computed so it needs to be executed like,

http://jsfiddle.net/LGveR/18/

this.selectedItem(1)().country

Upvotes: 1

Related Questions