Particularités
Sélection dans une liste
ember g helper include
import Ember from 'ember'; export function include(params) { const [items, value] = params; return items.indexOf(value) > -1; } export default Ember.Helper.helper(include);
Multiple
Template :
<select class="form-control" multiple onChange={{action "selectService"}}> {{#each model.services as |service|}} <option value={{service.id}} selected={{include model.selectedIds service.id}}>{{service.title}}</option> {{/each}} </select>
Classe dans Route handler :
const Services=Ember.Object.extend({ selectedIds: [], selectedServices: Ember.computed('selectedIds.[]', function() { return this.get('selectedIds').map((id) => { return this.get('services').findBy('id', id); }); }) });
Controller :
ember g controller select
import Controller from '@ember/controller'; export default Controller.extend({ actions:{ selectService:function(event) { const selectedIds = Ember.$(event.target).val(); let model=this.get('model'); model.set('selectedIds', selectedIds || []); } } });