samedi 16 juillet 2016

Ember howto use model field values in Controller

I am a newbie on Ember and break my head already a couple of hours how i can use the value of a model field in a controller ??

This is my model :

import DS from 'ember-data';

export default DS.Model.extend({
    id_address: DS.attr('number'),
    id_customer_fb: DS.attr('number'),
    id_customer: DS.attr('number'),
    id_supplier: DS.attr('number'),
    id_state: DS.attr('number'),
    id_country: DS.attr('number'),
    postcode:  DS.attr(),
    active: DS.attr('boolean'),
    address1: DS.attr(),
    address2: DS.attr(),
    city: DS.attr(),
    alias:  DS.attr(),
    company: DS.attr(),
    vat_number: DS.attr(),
    firstname: DS.attr(),
    lastname: DS.attr(),
    other: DS.attr(),
    phone: DS.attr(),
    phone_mobile: DS.attr(),
    deleted: DS.attr('boolean'),
    date_add: DS.attr('date'),
    date_upd: DS.attr('date')


});

This is my route :

import Ember from 'ember';
export default Ember.Route.extend({
    beforeModel: function(){

        if(!this.get('session.isAuthenticated')){
            this.transitionTo('application');
        }
   }, 

 model(params) {
    return Ember.RSVP.hash({
        customer: this.store.findRecord('customer', params.id),
        address: this.store.query('address', {
            orderBy: 'id_customer_fb',
            equalTo: parseInt(params.id)
        })
    });
   }
});

THIS IS MY CONTROLLER :

import Ember from 'ember';


 const genders = [
    { title: 'Dhr.',  id_gender: '1' },
    { title: 'Mevr.',  id_gender: '2' },
 ];



 export default Ember.Controller.extend({

     genders: genders,
     selection: genders[1]**,   <== THIS '1' MUST BE REPLACED WITH THE VALUE OF models.customer.id_gender ?????**


    actions: {
        chooseDestination(genders) {
        this.set('selection', genders);
        },
  }
});

I would that the value '1' in this genders array could be the value of model.customer.id_gender ??? ` thanks in advance !




Aucun commentaire:

Enregistrer un commentaire