Last active
June 12, 2016 22:19
-
-
Save cafreeman/00aeaddf8cea82f1c271f838e39f4483 to your computer and use it in GitHub Desktop.
filter_v_filterBy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
options: ["Xie Q.", "blah"], | |
data: [ | |
{ | |
"frequency": 2, | |
"name": "Lee J." | |
}, | |
{ | |
"frequency": 2, | |
"name": "Xie Q." | |
}, | |
{ | |
"frequency": 2, | |
"name": "Yu R." | |
}, | |
{ | |
"frequency": 2, | |
"title": "some title", | |
"name": "blah", | |
}, | |
], | |
filtered: null, | |
actions: { | |
doFilterBy() { | |
// This works because we're only passing a single value to `filterBy` | |
let filteredBy = this.get('data').filterBy('name', 'blah'); | |
this.set('filtered', filteredBy); | |
}, | |
doFilter() { | |
// To filter against an array of values, we use `indexOf` to check each enumerated value against | |
// the test array. | |
let filtered = this.get('data').filter((v) => { | |
return this.get('options').indexOf(v.name) !== -1; | |
}); | |
this.set('filtered', filtered); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.8.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.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment