mercredi 3 juin 2015

Ember select default value

I am unable to select a default value in an ember select. Here is what the code looks like

Models:

rfwa.Field = DS.Model.extend({
    Name: DS.attr('string'),
    FieldTypeId: DS.attr('number'),
    FieldType: DS.belongsTo('fieldType'),

});

rfwa.FieldType = DS.Model.extend({
    Name: DS.attr('string')
});

Route:

rfwa.FieldRoute = Ember.Route.extend({
   model: function (params) {
       return Ember.RSVP.hash({
            field: route.store.find('field', params.field_id),
            fieldTypes: route.store.find('fieldType')
       });
    },
    setupController: function (controller, model) {
        controller.set('fieldTypes', model.fieldTypes);
        controller.set('model', model.field);
    }
});

Template:

<script type="text/x-handlebars" data-template-name="Field">
   {{input value=model.Name class="form-control" id="Name"}}
   {{view "select" content=fieldTypes optionValuePath="content.id" optionLabelPath="content.Name" value=model.FieldTypeId classNames="form-dropdown"}}
</script>

I have fiddled with a lot of possibilities using selection and value in the view. Creating functions that returns a fieldType for selection. So far, nothing has worked. there has to be something I am doing wrong.

I am using Ember 1.12.1 with Ember-data 1.0.0-beta18.

Currently with what I have pasted, it sets my model.FieldTypeId to undefined when the page loads.




Aucun commentaire:

Enregistrer un commentaire