简体   繁体   中英

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

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

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

this.selectedItem(1)().country

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM