Skip to content

Instantly share code, notes, and snippets.

@seanjohnson08
Last active February 15, 2017 00:58
Show Gist options
  • Select an option

  • Save seanjohnson08/34cd258153ca57ba28b2e1424a0a1fe3 to your computer and use it in GitHub Desktop.

Select an option

Save seanjohnson08/34cd258153ca57ba28b2e1424a0a1fe3 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
things: [{ color: 'green' }, { color: 'red' }],
filterBy: Ember.computed.filterBy('things', 'color', 'green'),
filter: Ember.computed.filter('things', function(thing) {
return thing.color === 'green';
}),
actions: {
addThing(color) {
this.get('things').pushObject({ color });
}
}
});
<h1>FilterBy</h1>
{{#each filterBy as |thing|}}
{{thing.color}}
{{/each}}
<h1>Filter</h1>
{{#each filter as |thing|}}
{{thing.color}}
{{/each}}
<h1>Add things</h1>
<button {{action "addThing" "green"}}>Green thing</button>
<button {{action "addThing" "red"}}>Red thing</button>
<br>
<br>
{
"version": "0.11.0",
"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.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment