Skip to content

Instantly share code, notes, and snippets.

@miguelcobain
Created November 14, 2016 22:06
Show Gist options
  • Save miguelcobain/0b22845d742582fab01e752a68ed298a to your computer and use it in GitHub Desktop.
Save miguelcobain/0b22845d742582fab01e752a68ed298a to your computer and use it in GitHub Desktop.
array change
import Ember from 'ember';
const { Controller, computed } = Ember;
let Item = Ember.Object.extend({
now: computed(function() {
return new Date();
})
});
export default Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
let items = [1, 2, 3, 4, 5].map((i) => {
return Item.create({
id: i,
name: `Item ${i}`,
});
});
this.set('items', items);
},
actions: {
splice() {
let items = this.get('items');
this.set('items', items.splice(1, 2));
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<ul>
{{#each items as |i|}}
<li>{{i.id}} - {{i.name}}- {{i.now}}</li>
{{/each}}
</ul>
<br>
<button onclick={{action "splice"}}>More</button>
{
"version": "0.10.6",
"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.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment