Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active August 24, 2016 20:21
Show Gist options
  • Save phillipkregg/2989707e51459a65d23691ae7bd723b4 to your computer and use it in GitHub Desktop.
Save phillipkregg/2989707e51459a65d23691ae7bd723b4 to your computer and use it in GitHub Desktop.
Filtered List
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
filterValue: undefined,
albums: Ember.computed(function() {
console.log(this.store.peekAll('album'));
return this.store.peekAll('album');
}),
filteredAlbums: Ember.computed('filterValue', function() {
var me = this;
if (this.get('filterValue')) {
return this.get('albums').filter(function(album) {
return album.get('title').indexOf(me.get('filterValue')) >= 0;
})
} else {
return this.get('albums');
}
})
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
title: attr(),
artist: attr(),
songCount: attr()
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.push({
data: [{
id: 1,
type: 'album',
attributes: {
title: 'Fewer Moving Parts',
artist: 'David Bazan',
songCount: 10
},
relationships: {}
}, {
id: 2,
type: 'album',
attributes: {
title: 'Calgary b/w I Can\'t Make You Love Me/Nick Of Time',
artist: 'Bon Iver',
songCount: 2
},
relationships: {}
}]
});
},
actions: {
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{input value=filterValue class="light" placeholder="Filter By City"}}
{{yield results}}
{{#each filteredAlbums as |album|}}
<li>{{album.title}}</li>
{{/each}}
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment