I am trying to achieve the following with knockout with some difficulty:
- Bind a select form element … this works
- Display the selected option via a ko.observable … this works
- Use the ko.observable from #2 inside a ko.computed variable… I cant figure this out.
Here is a Fiddle of my attempt so far. any ideas?
Computed observables are evaluated immediately. When you create your
viewModelvariable in an object literal like in your example, it can’t be used yet in your computed observable.A couple choices. Write it like:
or
Also,
selectedOptionValueis an observable, so you would read its value by calling it as a function with no arguments like:this.selectedOptionValue()