jeudi 16 avril 2015

Trouble with ember select

I am trying to get a simple belongsTo relationship working with an HTML select element.


My app records students. Each student is assigned to a category.


I have a category model:



import DS from "ember-data";

export default DS.Model.extend({
code: DS.attr('string'),
description: DS.attr('string')
});


And a student model which - amongst many other things - belongs to a category.



import DS from "ember-data";

export default DS.Model.extend({
//...
category: DS.belongsTo('category', {async: true}),
//...
});


I want to allow the user to select the students category in a template so my route loads in a list of category objects:



import Ember from "ember";

export default Ember.Route.extend({
model: function(params) {
return this.store.find('student', params.student_id);
},
setupController: function(controller, model) {
this._super(controller, model);
//...
controller.set('categories', this.store.find('category'));
//...
}
});


My template includes this:



<label>Category:&nbsp;</label>
{{view "select"
content=categories
optionValuePath="content"
optionLabelPath="content.description"
selection=category}}


My expectation is that this will allow me to choose an item from the list and it will update my models category accordingly.


What actually happens is that the list works but if I change the selection the select element goes blank.


Have I done this correctly? Is there a pattern I am missing?


Aucun commentaire:

Enregistrer un commentaire