Skip to content

Instantly share code, notes, and snippets.

@tcjr
Last active April 10, 2018 17:15
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 tcjr/e453fcf9cb9964caa2df438b0751c7e9 to your computer and use it in GitHub Desktop.
Save tcjr/e453fcf9cb9964caa2df438b0751c7e9 to your computer and use it in GitHub Desktop.
ember-awesome-macros brace expansion json
import Ember from 'ember';
import { array } from 'ember-awesome-macros';
export default Ember.Controller.extend({
selectedField: 'id',
data: [
{fname: 'George', "last name": "Orwell", id:1 },
{fname: 'Michelle', "last name": "Obama", id:2 },
{fname: 'George', "last name": "Washington", id:3 },
{fname: 'Martha', "last name": "Washington", id:4 }
],
uniques: array.uniqBy('data', 'selectedField')
});
<button {{action (mut selectedField) 'id'}}>use 'id'</button>
<button {{action (mut selectedField) 'fname'}}>use 'fname'</button>
<button {{action (mut selectedField) 'last name'}}>use 'last name'</button>
<h1>Selected field: '{{selectedField}}'</h1>
<br>
<br>
<h2>Values:</h2>
<ul>
{{#each uniques as |val|}}
<li>{{val.id}}: {{val.fname}} {{val.[last name]}}</li>
{{/each}}
</ul>
{{outlet}}
<br>
<br>
{
"version": "0.13.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": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-awesome-macros": "0.41.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment