Skip to content

Instantly share code, notes, and snippets.

@HERRKIN
Last active August 29, 2015 14:07
Show Gist options
  • Save HERRKIN/cb4552ce04c47f229381 to your computer and use it in GitHub Desktop.
Save HERRKIN/cb4552ce04c47f229381 to your computer and use it in GitHub Desktop.
ember select doesnt show properly the selected one
pet template/////////////////////
<h1>
{{nombre}} {{color}}
</h1>
<p>pertenece a:
{{dueno.nombre}} {{dueno.apellido}}</p>
{{#if editando}}
<form role="form">
<div class="form-group">
<label for="nombre">nombre</label>
{{input id='nombre' class="form-control" value=nombre}}
</div>
<div class="form-group">
<label for="color">color</label>
{{input id='color' class="form-control" value = color}}
</div>
seleccionado {{selectedPersona.id}}
{{view Ember.Select selection=dueno content=personas optionValuePath="content.id"
optionLabelPath="content.nombre"}}
<button type="submit" class="btn btn-success" {{action 'modificar'}}>Guardar</button>
</form>
{{/if}}
{{#unless editando}}
<a href="#" class="btn btn-success" {{action 'editar'}}>Editar</a>
<a href="#" class="btn btn-danger" {{action 'eliminar'}}>Eliminar</a>
{{/unless}}
/////////////////////////////////////////////////////
pet router//////////////////////////////////////////
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return this.store.find('pet', params.pet_id);
},
setupController: function(controller, model) {
this._super(controller, model);
// Switch out arr with whatever your personas array is
controller.set('personas', this.store.all('persona'));
}
});
//////////////////////////////////////////////////////////
pet controller ///////////////////////////////////////
import Ember from 'ember';
export default Ember.ObjectController.extend({
needs:['personas', 'persona'],
editando: false,
actions: {
editar: function() {
this.set('editando', true);
},
modificar: function() {
this.set('editando', false);
var m = this.get('model');
console.log('selected '+this.selectedPersona);
console.log('duenio '+m.get('dueno'));
m.save();
},
eliminar: function () {
var pet = this.get('model');
pet.deleteRecord();
pet.save();
}
}
});
/////////////////////////////////////////
pet model //////////////////////////////
import DS from 'ember-data';
export default DS.Model.extend({
nombre:DS.attr('string'),
color:DS.attr('string'),
dueno:DS.belongsTo('persona',{async:true})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment