Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Last active April 12, 2016 06:24
Show Gist options
  • Save kidGodzilla/5b62cda6c16e43d6c5a8dc285306db90 to your computer and use it in GitHub Desktop.
Save kidGodzilla/5b62cda6c16e43d6c5a8dc285306db90 to your computer and use it in GitHub Desktop.
Passing a Model
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('friend', { path: '/friend/:item_id' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model: function () {
return [{
id: 'james',
name: "James",
age: 28,
location: "Seattle"
},{
id: 'josh',
name: "Josh",
age: 21,
location: "London"
},{
id: 'jackie',
name: "Jackie",
age: 26,
location: "Los Angeles"
}];
}
});
<h1>Passing a model through a link</h1>
<p>In this example, we pass an item from our model through the link-to helper to the `/friend/[id]`. There, it will become the model for this child route, and it's information will be displayed.</p>
{{#each model as |friend|}}
{{#link-to 'friend' friend}}{{friend.name}}{{/link-to}}
{{/each}}
<br>
<br>
{{outlet}}
<br>
<br>
<p>
Name: {{model.name}},
{{model.age}}.
{{model.location}}.
</p>
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"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.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment