Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember How to pass a variable to Ember.computed.filterBy

Imagine I have a component with 2 properties: How would I be able to create a computed property based on the localID property and the Ember.computed.filterBy macro ?

localID: 2,

data: [
{
    id:1,
    values: [1,2,3]
},
{
    id:2,
    values: [4,5,6]
},
{
    id:3,
    values: [7,8,9]
}],

I have tried:

filteredData: Ember.computed.filterBy('data', 'id', 'localID') // localID gets treated as a string

filteredData: Ember.computed.filterBy('data', 'id', localID) // localID not defined

filteredData: Ember.computed.filterBy('data', 'id', this.get('localID')) // 'this' not valid in this context..

filteredData: Ember.computed.filterBy('data', 'id', ${localID}) // etc..

Nothing seems to work.. Of course if I statically input my value there it works but I wanted it to reference the other property in this case localID as it will be passed from a controller.

Thanks for any help..

like image 876
Fred John Avatar asked Dec 21 '25 01:12

Fred John


1 Answers

Rewrite your property as

filteredData: function() {
  return this.get('data').filterBy('id', this.get('localID'));
}.property('[email protected]')

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!