Skip to content

Instantly share code, notes, and snippets.

@sly7-7
Created October 19, 2015 12:34
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 sly7-7/95cac8de902275d6f8d4 to your computer and use it in GitHub Desktop.
Save sly7-7/95cac8de902275d6f8d4 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
var array = [{id: 42, name: 'blah'},
{id: 43, name: 'oh'},
{id: 44, name: 'ah'}];
export default Ember.Controller.extend({
appName:'Ember Twiddle',
someProp: true,
//things: [42,43, 44],
things: [{id: 42, name: 'blah'},
{id: 43, name: 'oh'},
{id: 44, name: 'ah'}],
sortedThings: Ember.computed('someProp', function() {
var someProp = this.get('someProp');
console.log(this.get('things'));
return this.get('things').sort(function(a,b) {
return someProp === true ? a.id-b.id : b.id-a.id;
});
}),
actions: {
changeThing: function() {
this.toggleProperty('someProp');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{#each sortedThings key="id" as |thing|}}
{{thing.id}}
{{/each}}
{{my-component things=sortedThings}}
<button {{action 'changeThing' on='click'}}>
hop
</button>
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
});
{{#each things key="id" as |thing|}}
{{thing.id}}
{{/each}}
{
"version": "0.4.13",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment