I’m starting to build an ember app. I’m almost done with the API, which I know works. I’m able to properly display with .getJSON but not with the store.find method, instead I get an unknown type error, which i’m guessing amounts to the data not being properly retrieved. I am using ember inspector in Chrome, but I don’t see where it’s trying to get the JSON, i’m assuming it should be “api/projects”.
Also, i’m not seeing any network requests when using store.find, only see them with getJSON
thanks!
window.App = Ember.Application.create();
App.Router.map(function() {
this.route('projects')
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
});
App.Projects = DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string')
});
this works:
App.ProjectsRoute = Ember.Route.extend({
model: function(){
return $.getJSON("api/projects").then(function(data){
return data.projects;
});
}
});
this does not:
App.ProjectsRoute = Ember.Route.extend({
model: function(){
return this.store.find('projects');
}
});
ERROR:
Error while processing route: projects Cannot read property 'typeKey' of undefined TypeError: Cannot read property 'typeKey' of undefined
at DS.RESTAdapter.DS.Adapter.extend.findAll (http://trgmanage.app/js/libs/ember-data.min.js:9:28455)
at Object.Ember.assert (http://trgmanage.app/js/libs/ember-1.10.0.debug.js:3934:27)
at DS.Store.Ember.Object.extend.fetchAll (http://trgmanage.app/js/libs/ember-data.min.js:8:20000)
at DS.Store.Ember.Object.extend.findAll (http://trgmanage.app/js/libs/ember-data.min.js:8:19773)
at DS.Store.Ember.Object.extend.find (http://trgmanage.app/js/libs/ember-data.min.js:8:16174)
at App.ProjectsRoute.Ember.Route.extend.model (http://trgmanage.app/js/app.js:13:23)
at EmberObject.extend.deserialize (http://trgmanage.app/js/libs/ember-1.10.0.debug.js:23915:21)
at applyHook (http://trgmanage.app/js/libs/ember-1.10.0.debug.js:50118:30)
at Object.HandlerInfo.runSharedModelHook (http://trgmanage.app/js/libs/ember-1.10.0.debug.js:48139:22)
at Object.subclass.getModel (http://trgmanage.app/js/libs/ember-1.10.0.debug.js:48365:21)
JSON Response: (Formatted by JSONview in Chrome)
{
projects: [
{
id: 1,
title: "this is going",
description: "Aspernatur eum placeat consequuntur. Hic totam molestias nemo. Aut et aut aut earum deserunt impedit. Voluptatum omnis quae est corporis dicta voluptas ut quod. Laboriosam impedit sed eos ut rerum aliquid."
},
{
id: 2,
title: "twinkle1",
description: "Atque nihil ratione dolorem neque odio ex. Facere eaque veritatis incidunt veniam vitae. Culpa voluptatum accusamus voluptate voluptate aut nihil. Sunt adipisci deleniti nihil quia dolorem. Dolor nemo et explicabo minima eos iusto autem. Non qui eveniet rem aliquid et."
},
{
id: 3,
title: "Culpa quibusdam perspiciatis id dolorem consequuntur.",
description: "Ut veritatis nihil ducimus consequuntur nulla. Facilis qui error enim iste soluta dolore. Optio accusamus aliquam dicta. Voluptatem sint dolores quaerat quam ut. Deleniti iste quae molestias amet velit."
}
]
}
JSON Response unformatted:
{"projects":[{"id":1,"title":"this is going","description":"Aspernatur eum placeat consequuntur. Hic totam molestias nemo. Aut et aut aut earum deserunt impedit. Voluptatum omnis quae est corporis dicta voluptas ut quod. Laboriosam impedit sed eos ut rerum aliquid."},{"id":2,"title":"twinkle1","description":"Atque nihil ratione dolorem neque odio ex. Facere eaque veritatis incidunt veniam vitae. Culpa voluptatum accusamus voluptate voluptate aut nihil. Sunt adipisci deleniti nihil quia dolorem. Dolor nemo et explicabo minima eos iusto autem. Non qui eveniet rem aliquid et."},{"id":3,"title":"Culpa quibusdam perspiciatis id dolorem consequuntur.","description":"Ut veritatis nihil ducimus consequuntur nulla. Facilis qui error enim iste soluta dolore. Optio accusamus aliquam dicta. Voluptatem sint dolores quaerat quam ut. Deleniti iste quae molestias amet velit."}]}