Particularités
Sélection dans une liste
ember g helper include |
1 2 3 4 5 6 7 8 |
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 :
1 2 3 4 5 |
< 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 :
1 2 3 4 5 6 7 8 9 |
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 |
1 2 3 4 5 6 7 8 9 10 11 12 |
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 || []); } } }); |