Skip to content

Instantly share code, notes, and snippets.

@ryanto
Last active February 8, 2017 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanto/c820b8027dbb1beffaad2ccd27c145b6 to your computer and use it in GitHub Desktop.
Save ryanto/c820b8027dbb1beffaad2ccd27c145b6 to your computer and use it in GitHub Desktop.
flatMap
import Ember from 'ember';
export default Ember.Controller.extend({
posts: Ember.A([
Ember.Object.create({ author: { name: 'steve' } }),
Ember.Object.create({ author: { name: 'jill' } }),
Ember.Object.create({ author: { name: 'andy' } })
]),
authors: Ember.computed.mapBy('posts', 'author'),
names: Ember.computed.mapBy('authors', 'name'),
actions: {
addAuthor(name) {
let newPost = Ember.Object.create({ author: { name: name } });
this.get('posts').addObject(newPost);
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
{{#each authors as |author|}}
An author: {{author.name}}<br>
{{/each}}
<br><br>
<a href="#" {{action "addAuthor" "bill"}}>Add bill</a>
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment