HerrTeetrinken
HerrTeetrinken

Reputation: 33

knockout.js: edit selected object

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:

  1. displayed in the next two <selects>
  2. can be changed from those two <selects>

I'm halfway stuck in 1:

Where are my mistakes? How can I achieve this

EDIT: small change solves the last problem

Upvotes: 0

Views: 37

Answers (1)

tyler_mitchell
tyler_mitchell

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

Related Questions