Skip to content

Instantly share code, notes, and snippets.

@Subtletree
Created June 2, 2017 02:34

Revisions

  1. Subtletree created this gist Jun 2, 2017.
    26 changes: 26 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import Ember from 'ember';

    export default Ember.Controller.extend({
    appName: 'Ember Twiddle',

    arr: [{},{},{},{},{},{},{},{},{},{}],

    arrayLength: Ember.computed.alias('arr.length'),

    arrayObserver: Ember.observer('arr.length', function() {
    alert(this.get('arr.length'));
    }),

    actions: {

    add() {
    let newItem = {};
    this.get('arr').splice(4, 0, newItem);
    },

    remove(item) {
    this.get('arr').removeObject(item);
    }

    }
    });
    8 changes: 8 additions & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <h1>Welcome to {{appName}}</h1>

    {{#each arr as |item index|}}
    <p>item {{index}} <button {{action 'remove' item}}>x</button></p>

    {{/each}}

    Array length: {{arrayLength}} <button {{action 'add'}}>Add</button>
    19 changes: 19 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {
    "version": "0.12.1",
    "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.12.0",
    "ember-template-compiler": "2.12.0",
    "ember-testing": "2.12.0"
    },
    "addons": {
    "ember-data": "2.12.1"
    }
    }