jeudi 26 juillet 2018

Create a generic select for belongTo in Ember, stuck on having the select show the already existing value

I am trying to make a select element to set up a belongsTo relation.

The params of the componenent are :

collection: a collection of element displayed in the select colText: column of the collection displayed in the select. It's a string model: The model currently being edited relation: String of the name of the model to wich it belong to

hbs :

<select class="form-control"
onchange=>
  <option value=""></option>
  
    <option value= 
      selected=>
      
    </option>
  
</select>

JS :

import Ember from 'ember';

export default Ember.Component.extend({
  store: Ember.inject.service(),
  currentForeignId: Ember.computed(function(){
    debugger;
    return this.get('model').get(this.get('relation')).id
  }),
  actions:{
    selectValue(value){
      this.get('model').set(this.get('relation'),
        this.get('store').peekRecord( this.get('relation'), value ))
    }
  }
});

Despite all my attempts, I cannot make currentForeignId return an ID. I tried with a debbuger to display the value but I cannot access it.




Aucun commentaire:

Enregistrer un commentaire