Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Ember.Select to set association IDs

Tags:

ember.js

I am trying to use the Ember.Select control to set an association id on a model. However, I can't seem to get the control to bind it's selection to an id attribute instead of the entire model object. Is this by design in the Ember.Select control? I have the following in my template:

  {{view Ember.Select
         contentBinding="App.peopleController.content"
         selectionBinding="App.selectedPersonController.personId"
         optionLabelPath="content.fullName"
         optionValuePath="content.id"}}

Yet even with explicitly setting selectionBinding to the personId attribute it still seems to be binding to the person object. Full jsfiddle here: http://jsfiddle.net/PXVZb/10/

like image 336
Sean O'Hara Avatar asked Nov 14 '22 08:11

Sean O'Hara


1 Answers

I would suggest to bind the selected person to your App.selectedPersonController and create a property personId which binds to the persons id, see http://jsfiddle.net/PXVZb/11/

JS:

App.selectedPersonController = Ember.Object.create({
    personIdBinding: 'person.id'
});

Handlebars:

{{view Ember.Select
       contentBinding="App.peopleController.content"
       selectionBinding="App.selectedPersonController.person"
       optionLabelPath="content.fullName" }}
like image 64
pangratz Avatar answered Dec 26 '22 23:12

pangratz