Ember.Select selecting problems


#1

Hi all,

I have some problems loading and using Ember.Select… I’ll try to explain…

Using ember 1.0.0 and ember-data dated 2013-09-23 with restadapter

In the route I load the content (as usual) and another model to populate ad Ember.Select

Wus.InstallazioneRoute = Wus.AuthenticatedRoute.extend({
    setupController: function(controller, model) {
        controller.set('content', model);
        controller.set('prodottisel', controller.get('store').findAll('prodotto'));
    }
}); 

Here we have the models:

Wus.Installazione = DS.Model.extend({
	descrizione: DS.attr("string"),
	idprodotto: DS.attr("number")
});

Wus.Prodotto = DS.Model.extend({
	nome: DS.attr("string"),
	descrizione: DS.attr("string"),
});

so, in installazione.idprodotto I have to save the prodotto.id selected on the Ember.Select. This is the part of .hbs where the select reside:

{{view Ember.Select
    contentBinding="prodottisel"
    optionValuePath="content.id"
    optionLabelPath="content.nome"
    valueBinding="idprodotto"
}}

So, All is loaded right but the select dont select the right element on the combo… and because the valueBinding is on idprodotto the idprodotto is set to null. I’m making some mistakes? there’s a right way to do what I have to do? some samples?

thanks a lot :wink:


#2

I hope your question is, you don’t get the selected value in idprodotto. Use selectionBinding instead of valueBinding your idprodotto will not be null after selection. For more: http://emberjs.com/api/classes/Ember.Select.html


#3

Thanks a lot… also talking with joachimhs in IRC i change

idprodotto: DS.attr("number")

to

idprodotto: DS.belongsTo('prodotto')

and also I remove

optionValuePath="content.id"

from the Ember.Select and now is all correctly bound and working. Thanks to all :smile:

now I’m creating the serializer to send prodotto.id value to the server, but is another story :wink: