Skip to content

Instantly share code, notes, and snippets.

@benbabics
Last active January 18, 2017 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbabics/1d54d741b9f0b69b971cd6d96ed0c2a6 to your computer and use it in GitHub Desktop.
Save benbabics/1d54d741b9f0b69b971cd6d96ed0c2a6 to your computer and use it in GitHub Desktop.
checkbox-all-valid-items
import Ember from 'ember';
export default Ember.Component.extend({
defaultAllChecked: false,
allValidItems: Ember.computed.oneWay( 'defaultAllChecked' ),
isAllChecked: Ember.computed('allValidItems', 'items.[]', function() {
return this.get('allValidItems.length') === this.get('items.length');
})
});
console.clear();
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
allValidItems: Ember.computed('collection.@each.isValid', function() {
return this.get( 'collection' ).filter(function(item) {
return item.get( 'isValid' );
});
}),
collection: Em.A([
Em.Object.create({ name: 'foo', isValid: true }),
Em.Object.create({ name: 'bar', isValid: false }),
Em.Object.create({ name: 'baz', isValid: true })
])
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component items=collection allValidItems=allValidItems}}
<ul>
{{#each items as |item|}}
<li>{{ item.name }} {{input type="checkbox" checked=item.isValid}}</li>
{{/each}}
</ul>
<p>All Checked Items: {{ isAllChecked }}</p>
{
"version": "0.10.7",
"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.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment