Skip to content

Instantly share code, notes, and snippets.

@alexdiliberto
Last active March 30, 2017 02:20
Show Gist options
  • Save alexdiliberto/98db39c9da13f2d48060a96c3be04493 to your computer and use it in GitHub Desktop.
Save alexdiliberto/98db39c9da13f2d48060a96c3be04493 to your computer and use it in GitHub Desktop.
Ember 'Toggle All' Checkbox #1
import Ember from 'ember';
export default Ember.ArrayController.extend({
itemController: 'checkboxableItem',
selectedItems: Ember.computed.filterBy('', 'selected', true),
selectedCount: Ember.computed.alias('selectedItems.length'),
actions: {
removeSelected: function() {
var selectedItems = this.get('selectedItems').toArray();
this.removeObjects(selectedItems);
}
}
});
import Ember from 'ember';
export default Ember.ObjectController.extend({
selected: false
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
Ember.Object.create({ name: "Foo" }),
Ember.Object.create({ name: "Bar" }),
Ember.Object.create({ name: "Baz" })
];
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
<ul>
{{#each}}
<li>
{{input type="checkbox" checked=selected}}
{{name}}
</li>
{{/each}}
</ul>
{{selectedCount}} selected.
<button {{action "removeSelected"}}>Remove</button>
{
"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": "1.12.0",
"ember-template-compiler": "1.12.0",
"ember-testing": "1.12.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment