2
votes

I'm attempting to use Ember Select but the id's of the options seem to be changing based on the selection I choose.

I've mocked up a simplified scenario with books and authors and have the below Ember.Select

{{ view Ember.Select
          contentBinding="controller.authors"
          optionValuePath="content.id"
          optionLabelPath="content.name"
          valueBinding="book.author.id"
}}

The select works, but it changes the underlying list that it is bound (contentBinding), not just the valueBinding.

Based on the bizarre behavior I'm seeing I can only assume that I'm wiring up the paramaters wrong on the Ember.Select call, but I can't come up with the right combination.

The fiddle below shows what I mean:

Steps to reproduce: 1) Click run in fiddle. Sometimes I have to hit it more than once to get the selects to populate (not sure why, it may have something to do with the issue, or may just be fiddle) 2) Change any "author" via the drop down 3) Notice that not only does the id associated with the book's author change, but the ids in the list of authors also change. 4) Tell me why :).

http://jsfiddle.net/davepreston/h9dJt/

As you can probably tell, I'm pretty new to ember, so thanks for any help.

--Dave

2

2 Answers

1
votes

Modify your binding to,

view Ember.Select
          contentBinding="controller.authors"
          optionValuePath="content"
          optionLabelPath="content.name"
          valueBinding="book.author"

http://jsfiddle.net/h9dJt/4/

1
votes

The answer to 4) why?
This is because of the you have binding between value of selection with book.author.id so when the selection value changes, id of corresponding author also changes. This is the usual behavior of basic 2 way bindings of ember. In which if we bind 2 attributes, change of one changes the other one too.
id change is reflected in the list of authors because in the store we only have one instance of the record means book.author refer to the same record object (does not make a copy).