Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import Ember from 'ember';
  2.  
  3. const {
  4. Controller,
  5. ArrayProxy,
  6. computed,
  7. isBlank,
  8. isEqual
  9. } = Ember;
  10.  
  11. const DecoratedOptions = ArrayProxy.extend({
  12. objectAtContent(index) {
  13. let selectedValue = this.get('selectedValue');
  14. let value = this.get('content')[index];
  15. return {
  16. value,
  17. selected: isEqual(value, selectedValue)
  18. };
  19. }
  20. });
  21.  
  22. export default Controller.extend({
  23. selectedValue: null,
  24. options: ['foo', 'bar', 'baz'],
  25.  
  26. noValueSelected: computed('selectedValue', {
  27. get() {
  28. return isBlank(this.get('selectedValue'));
  29. }
  30. }),
  31.  
  32. decoratedOptions: computed('{selectedValue,options.[]}', {
  33. get() {
  34. let selectedValue = this.get('selectedValue');
  35. let content = this.get('options');
  36. return DecoratedOptions.create({ content, selectedValue });
  37. }
  38. })
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement