Reputation: 33
https://jsfiddle.net/7ueL5taw/36/
https://jsfiddle.net/7ueL5taw/38/
I have a list of objects displayed in <select>
, I can select one and I want to achieve, that it's properties a
and b
are:
<selects>
<selects>
I'm halfway stuck in 1:
TypeError: selected(...) is undefined
. <select>
is updating when selecting one of the entries, but
not the second, second one doesn't even have the elements. Where are my mistakes? How can I achieve this
EDIT: small change solves the last problem
Upvotes: 0
Views: 37
Reputation: 1747
You are trying to set the value of your select to a property within an undefined observable selected().b()
.
Quick fix: selected() != null ? selected().a() : null
<select style="width: 20%" data-bind="enable: selected, options: a, optionsCaption: 'Choose...', value: selected() != null ? selected().a() : null">
</select>
<select style="width: 20%" data-bind="enable: selected, options: b, optionsCaption: 'Choose...', value: selected() != null ? selected().b() : null">
</select>
See working fiddle
Upvotes: 2