Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Created February 7, 2018 11:26
Show Gist options
  • Save GavinJoyce/75e5e3aede64c033176c10266657530a to your computer and use it in GitHub Desktop.
Save GavinJoyce/75e5e3aede64c033176c10266657530a to your computer and use it in GitHub Desktop.
push unshift array
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super(...arguments);
this.set('items', Em.A(['111', '222', '333']));
},
actions: {
appendItem() {
this.get('items').pushObject('new');
},
insertItem() {
this.get('items').unshiftObject('new');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
Items: {{items}}
<ul>
{{#each items as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
<button onclick={{action 'insertItem'}}>Insert Item</button>
<button onclick={{action 'appendItem'}}>Append Item</button>
{
"version": "0.13.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": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment