Skip to content

Instantly share code, notes, and snippets.

@hjumeau
Last active January 11, 2016 14:10
Show Gist options
  • Save hjumeau/14fd58e4b13068e50c94 to your computer and use it in GitHub Desktop.
Save hjumeau/14fd58e4b13068e50c94 to your computer and use it in GitHub Desktop.
DynamicSegments
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember 2.0'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
model(params){
var posts = this.modelFor('posts');
return posts[params.post_id];
//return this.store.findRecord('post', params.post_id); => GET /posts/1
}
});
{{#link-to 'posts'}}retour{{/link-to}}
<br>
{{model.content}}
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return [
{id:0, content:'Ember is awsome'},
{id:1, content:'Ember is fast and furious'}
];
//return this.store.findAll('posts'); => GET /posts
}
});
{{#each model as |post|}}
{{#link-to 'post' post.id}}{{post.id}}{{/link-to}}
{{/each}}
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('posts');
this.route('post', { path: '/post/:post_id' });
});
export default Router;
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment