Reputation: 239
I'm pretty new to Ember, and I'm trying to set up a template that displays information about an external model (product). So I have an admin route:
App.AdminRoute = Ember.Route.extend({
model: function() {
var admin_brand = this.store.find('brand', 1);
return this.store.find('product', {brand: admin_brand});
}
});
controller:
App.AdminController = Ember.ArrayController.extend({
});
and template:
<script type="text/x-handlebars" data-template-name="admin">
<div class="row">
{{#each}}
{{name}}
{{/each}}
</div>
</script>
But I'm getting a JS error:
Error while processing route: admin undefined is not a function TypeError: undefined is not a function
I'm also using ember-data-django-rest-adapter for my actual data (which seems to be working fine otherwise). If I pass it a static array of objects in the route it works fine. Any ideas as to what I'm doing wrong? Also, is this even the correct way to go about this? Finally, is there a better way to debug these types of issues? I have the Chrome extension but it doesn't seem to help with these extremely generic errors, so any other tips on that would be awesome. Thanks very much for the help.
Upvotes: 1
Views: 258
Reputation: 2592
Assuming you are using ember data...
The issue is that the call to this.store.find('brand', 1)
returns a promise, not a value. In order to use the value in the call to this.store.find('product', {brand: admin_brand})
you would need to use .then()
to access the resolved value.
Something like this should work.
App.AdminRoute = Ember.Route.extend({
model: function() {
var self = this;
return self.store.find('brand', 1).then(function(admin_brand){
return self.store.find('product', {brand: admin_brand})
});
}
});
Upvotes: 1