Skip to content

Instantly share code, notes, and snippets.

@timrourke
Last active November 22, 2016 02:19
Show Gist options
  • Save timrourke/e83b04b06abffc4892d6f21b06ae10a9 to your computer and use it in GitHub Desktop.
Save timrourke/e83b04b06abffc4892d6f21b06ae10a9 to your computer and use it in GitHub Desktop.
MapBy
import Ember from 'ember';
export default Ember.Controller.extend({
field: Ember.computed(function() {
return Ember.Object.create({
fieldCategoryFields: [
Ember.Object.create({
fieldCategory: Ember.Object.create({
name: 'Category 1'
})
}),
Ember.Object.create({
fieldCategory: Ember.Object.create({
name: 'Category 2'
})
}),
Ember.Object.create({
fieldCategory: Ember.Object.create({
name: 'Category 3'
})
})
]
})
}),
categoryNames: Ember.computed.mapBy('field.fieldCategoryFields', 'fieldCategory.name')
});
<h1>MapBy</h1>
<br>
<br>
{{#each categoryNames as |name|}}
{{name}}
{{/each}}
<br>
<br>
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment