Skip to content

Instantly share code, notes, and snippets.

@astronomersiva
Last active August 1, 2016 19:27
Show Gist options
  • Save astronomersiva/c03e039a80cae64d7d779ff3cdecac76 to your computer and use it in GitHub Desktop.
Save astronomersiva/c03e039a80cae64d7d779ff3cdecac76 to your computer and use it in GitHub Desktop.
glimmer
import Ember from 'ember';
export default Ember.Controller.extend({
fields: Ember.A(),
actions: {
// doesn't work
addField( ) {
let fields = this.get('fields');
fields.insertAt(0, {
label: '1'
});
this.set('fields', fields);
},
// doesn't work when the line 42 is updated to
// fields.objectAt(1) or fields.objectAt(2)
// addField( ) {
// let fields = this.get('fields');
// fields.pushObject({
// label: '1'
// });
// this.set('fields', fields);
// },
// works when the line 42 is updated to
// fields.objectAt(1) or fields.objectAt(2)
// addField( ) {
// let fields = this.get('fields');
// fields.pushObjects([{
// label: '1'
// }, {
// label: '2'
// }]);
// this.set('fields', fields);
// },
addToField( ) {
let fields = this.get('fields');
let currentField = fields.objectAt(0);
let label = currentField.label + '1';
Ember.set(currentField, 'label', label);
console.log(fields, currentField);
}
}
});
{{#each fields as |field|}}
<p>{{field.label}}</p>
{{/each}}
<button {{action 'addField'}}>Add field</button>
<button {{action 'addToField'}}>Append to field </button>
<br>
<br>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "alpha",
"ember-data": "2.7.0",
"ember-template-compiler": "alpha"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment