Skip to content

Instantly share code, notes, and snippets.

@grapho
Forked from CostaRico/application.controller.js
Last active February 16, 2016 15:25
Show Gist options
  • Save grapho/f6a6b5b91adcd498993c to your computer and use it in GitHub Desktop.
Save grapho/f6a6b5b91adcd498993c to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
this.items = [
{ id: 1, name: 'first' },
{ id: 2, name: 'second' },
{ id: 3, name: 'third' },
{ id: 4, name: 'fourth' }
];
this.selectedItems = [];
},
actions: {
valueHasChanged(item, isChecked){
if (isChecked) {
this.get('selectedItems').addObject(item);
}
else {
this.get('selectedItems').removeObject(item);
}
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<table>
<tr>
<th>Selected</th>
<th>Items</th>
</tr>
{{#each items as |item|}}
<tr>
<td>
<input type="checkbox" onchange={{action (action "valueHasChanged" item) value="target.checked"}}>
</td>
<td>{{item.name}}</td>
</tr>
{{/each}}
</table>
<br>
<br>
<p>Your Selected Items:</p>
<ul>
{{#each selectedItems as |item|}}
<li>{{item.name}}</li>
{{else}}
<em>No items selected</em>
{{/each}}
</ul>
{
"version": "0.5.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.3.1",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "2.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment