Is it possible to filterBy multiple values in emberjs?
I am trying to filter items in a table with different filtering variables and I'm having trouble doing so with more than one of those variables.
Can anyone help out? I'm ne to emberjs and eager to learn. Thanks in advance.
Is it possible to filterBy multiple values in emberjs?
I am trying to filter items in a table with different filtering variables and I'm having trouble doing so with more than one of those variables.
Can anyone help out? I'm ne to emberjs and eager to learn. Thanks in advance.
Share Improve this question asked Jan 23, 2015 at 19:41 FutoRickyFutoRicky 1,0432 gold badges10 silver badges24 bronze badges2 Answers
Reset to default 10You can't pass multiple properties into the same filterBy
, but you can filterBy
on the same array 2 times, i.e. chain your filterBy
calls if that makes sense.
See the following answer I recently gave (here) for a working demo of what I am talking about
So, in short, if you have an array arr and you want to filter it by country
and name
properties for example, you would do:
arr.filterBy('country', countryName).filterBy('name', 'Josh')
You can also just use the filter
(as opposed to filterBy
) method and filter things any way you would like.
I blogged a solution at http://www.emberdaily./2019/02/25/filter-by-multiple-values/
Essentially,
this.get('myProjects').filter(project => project.get('status') === 'done' || project.get('status') === 'active');