Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active July 24, 2018 20:30
Show Gist options
  • Save phillipkregg/5c3224fa447b0cd39089320affd9a789 to your computer and use it in GitHub Desktop.
Save phillipkregg/5c3224fa447b0cd39089320affd9a789 to your computer and use it in GitHub Desktop.
Check Boxes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
testArray: [
Ember.Object.create({name: 'first', isChecked: true}),
Ember.Object.create({name: 'second', isChecked: true}),
Ember.Object.create({name: 'third', isChecked: true}),
Ember.Object.create({name: 'fourth', isChecked: true})
],
actions: {
toggleChecked() {
var testArray = this.get('testArray');
var i;
for (i=0; i < testArray.length; i++) {
if (testArray[i].isChecked) {
testArray[i].set('isChecked', false);
} else {
testArray[i].set('isChecked', true);
}
}
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{#each testArray as |testItem|}}
<input type="checkbox" checked={{if testItem.isChecked 'checked'}} />
{{/each}}
<br>
<br>
<button {{action 'toggleChecked' ''}}>Toggle Checked</button>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment