Skip to content

Instantly share code, notes, and snippets.

@rogatty
Created March 25, 2016 07:32
Show Gist options
  • Save rogatty/b1aaaac6268fa06fe7d7 to your computer and use it in GitHub Desktop.
Save rogatty/b1aaaac6268fa06fe7d7 to your computer and use it in GitHub Desktop.
insertAt
import Ember from 'ember';
export default Ember.Controller.extend({
lastPost: 0,
init() {
this.data = {
entities: []
};
},
actions: {
addPost() {
this.get('data.entities').insertAt(0, this.get('lastPost'));
this.incrementProperty('lastPost');
}
}
});
All posts:
<ul>
{{#each data.entities as |post|}}
<li>{{post}}</li>
{{/each}}
</ul>
<button {{action 'addPost'}}>Add post</button>
{
"version": "0.7.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": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/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.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment