Skip to content

Instantly share code, notes, and snippets.

@trabus
Last active October 19, 2015 22:58
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 trabus/3dfcce6400eadcab1e72 to your computer and use it in GitHub Desktop.
Save trabus/3dfcce6400eadcab1e72 to your computer and use it in GitHub Desktop.
demo for brandon
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
initData: Ember.on('init',function(){
// this would normally happen with the route model hook
// when the data response comes back, this happens automatically behind the scenes
this.store.pushPayload({yearbooks:[
{id: 1, name: 'yearbook 1'},
{id: 2, name: 'yearbook 2'},
{id: 3, name: 'yearbook 3'}
]});
}),
count: 3,
actions: {
pushModel: function(){
var records = {yearbooks: []};
var count = this.get('count')
for(var i = count; i < count + 3; i++){
records.yearbooks.push({
id: i,
name: 'yearbook ' + i
});
console.log(i);
}
// this happens automatically when data is received
this.store.pushPayload(records);
this.set('count', count+3)
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params){
// this method only looks for local records
// normally we'd use find, which makes a network request
return this.store.peekAll('yearbook');
},
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<h2>yearbooks: </h2>
<button {{action 'pushModel'}}>add to model</button>
<ul>
{{#each model as |yearbook|}}
<li>{{yearbook.name}}</li>
{{/each}}
</ul>
<br>
<br>
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr()
});
{
"version": "0.4.13",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment