Skip to content

Instantly share code, notes, and snippets.

@Kilowhisky
Last active October 7, 2015 15:28
Show Gist options
  • Save Kilowhisky/f5b3a5f20af5a825e684 to your computer and use it in GitHub Desktop.
Save Kilowhisky/f5b3a5f20af5a825e684 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Controller.extend({
filterStartRange: 0,
filterStopRange: 5000,
filterRecomputed: 0,
filtered: Ember.computed.filter('model', function(item) {
this.incrementProperty('filterRecomputed');
return item.id > this.get('filterStartRange') && item.id < this.get('filterStopRange');
}).property('model','filterStartRange','filterStopRange')
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
var arr = [];
for(var i = 0; i < 300; i++){
arr.pushObject({
id: i,
text: `Index ${i}.`
});
}
return arr;
},
actions: {
addItem: function(){
var model = this.modelFor(this.routeName);
var lastItem = model.get('lastObject');
var newIndex = lastItem.id + 1;
model.pushObject({
id: newIndex,
text: 'Index' + newIndex
});
}
}
});
<h3>Filter</h3>
<div>
Start Index: {{input value=filterStartRange type='number'}}
</div>
<div>
Stop Index: {{input value=filterStopRange type='number'}}
</div>
<div>Filter Recomputed #: {{filterRecomputed}}</div>
<button type="button" {{action 'addItem'}}>Add Item after end index</button>
<h3>Output</h3>
{{#each filtered as |item|}}
<div>
<span>ID: {{item.id}}</span>
<span>TEXT: {{item.text}}</span>
</div>
{{/each}}
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "http://builds.emberjs.com/release/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "http://builds.emberjs.com/release/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment