Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Created April 12, 2016 07:13
Show Gist options
  • Save kidGodzilla/6e2619874ec3257b597132d757a555cf to your computer and use it in GitHub Desktop.
Save kidGodzilla/6e2619874ec3257b597132d757a555cf to your computer and use it in GitHub Desktop.
Ember Data
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
addFriend: function () {
var friend = this.store.createRecord('friend', {
name: this.get('name'),
age: this.get('age'),
location: this.get('location')
});
// friend.save();
}
}
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
age: DS.attr('number'),
location: DS.attr('string')
});
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 this.store.findAll('friend');
}
});
<h1>Ember Data Example</h1>
<p>This works similar to the previous example, but it uses `Ember-data` as it's data store instead of a static model.</p>
{{#each model as |friend|}}
{{#link-to 'friend' friend}}{{friend.name}}{{/link-to}}
{{/each}}
<br>
<br>
{{outlet}}
<br>
<br>
<h4>Make a New Friend</h4>
<span style="display:inline-block;width:100px">Name:</span>
{{input value=name}} <br>
<span style="display:inline-block;width:100px">Age:</span>
{{input value=age}} <br>
<span style="display:inline-block;width:100px">Location:</span>
{{input value=location}}
<p style="margin-left: 136px">
<button {{action 'addFriend'}}>Add New Friend</button>
</p>
<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