简体   繁体   中英

Switched over js object to Ember Data model using Fixture Adapter and keep getting “Cannot call method 'findAll' of undefined” error

I'm working through the Code School Ember.js course and I have a Product model that is being loaded via the Fixture Adapter. My issue is that whenever I click on the 'products' link, linking to '/products' I get an error reading:

Error while loading route: TypeError: Cannot call method 'findAll' of undefined

My ProductsRoute looks like:

App.ProductsRoute = Ember.Route.extend({
    model: function() {
        return this.store.findAll('product');
    }
});

And the route fails to render.

Before I started using Ember Data and the Fixture adapter I was just using a js array of objects and calling it in the model: property of my Route object, which worked fine.

Here's my jsbin, minus the Ember Data Library:

http://emberjs.jsbin.com/zicofeku/1/edit

And here's an image of my console error:

在此处输入图片说明

I assume you're trying to get all Product records? In this case just use find with no parameters. See the docs for details.

Your code should look like:

App.ProductsRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('product');
    }
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM