I am working on an Ember CLI project (version 0.0.46)
While trying to use Ember Arrays findBy() inside a computed property, I get following error:
Uncaught TypeError: Cannot read property 'findBy' of undefined
- I have checked the locations array. It contains 2 objects before the findBy() is used on it.
Template
{{view Ember.Select
content=locations
value=locationId
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="- Please select a Location -"
class="form-control input-md"
selection=selectedLocation
}}
Computed Property:
selectedLocation:function(){
var locations = this.get('controllers.xyz.locations');
var matchedLoc =locations.findBy('id','loc2');
return matchedLoc;
}.property('controllers.xyz.locations')
- Note: For some reason, the above logic works fine when I use it inside the actions hook. Also, the locations array is null only when the first call is made to the computed property.
Any help will be appreciated. Thanks!
locations
is undefined. When did you "check the locations array"? Put a console.log after the assignment to locations. BTW, in what context are you definingselectedLocation
? It may be that this function is getting called whenmodel.locations
is still null, and will be called again later whenmodel.locations
is set. Try adding.property('model.locations')
, and doing a check formodel.locations
being null before trying to callfindBy
. - user663031