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
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')
Any help will be appreciated. Thanks!
It is likely that this function is getting called when model.locations
is still null, and will be called again later when model.locations is set. Add .property('model.locations')
, and do a check for model.locations
being null before trying to call findBy
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.