Last active
August 29, 2015 14:27
-
-
Save aortbals/02ddca9b6c89f2f8f92b to your computer and use it in GitHub Desktop.
Array Computed Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
items: [ | |
{ name: 'Fuu' }, | |
{ name: 'Bar' }, | |
{ name: 'Baz' }, | |
{ name: 'Qix' } | |
], | |
computedBasic: Ember.computed('items', function() { | |
return this.get('items').mapBy('name'); | |
}), | |
computedArray: Ember.computed('items.[]', function() { | |
return this.get('items').mapBy('name'); | |
}), | |
computedEach: Ember.computed('items.@each', function() { | |
return this.get('items').mapBy('name'); | |
}), | |
computedEachChained: Ember.computed('[email protected]', function() { | |
return this.get('items').mapBy('name'); | |
}), | |
actions: { | |
add(item) { | |
this.get('items').addObject({ name: item }) | |
}, | |
remove(item) { | |
this.get('items').removeObject(item) | |
}, | |
swap() { | |
this.set('items', [{ name: 'fuu' }, { name: 'bar' }]) | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.8", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.8/ember.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.9/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.8/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment