在我学习Ember的过程中,我试图让Ember向/ api / posts发出GET请求,并通过把手显示帖子列表。
现在,它已经成功获得了get请求,但chrome会弹出这些错误 -
TypeError: undefined is not a function
at DS.JSONSerializer.DS.Serializer.extend.configureSideloadMappingForType (http://localhost:3000/assets/ember-data.js?body=1:7798:10)
at DS.JSONSerializer.DS.Serializer.extend.sideload (http://localhost:3000/assets/ember-data.js?body=1:7768:10)
at DS.JSONSerializer.DS.Serializer.extend.extractMany (http://localhost:3000/assets/ember-data.js?body=1:7692:10)
at superWrapper [as extractMany] (http://localhost:3000/assets/ember.js?body=1:1293:16)
at DS.Adapter.Ember.Object.extend.didFindAll (http://localhost:3000/assets/ember-data.js?body=1:8307:16)
at http://localhost:3000/assets/ember-data.js?body=1:9894:15
at invokeCallback (http://localhost:3000/assets/ember.js?body=1:10014:19)
at publish (http://localhost:3000/assets/ember.js?body=1:9684:9)
at publishFulfillment (http://localhost:3000/assets/ember.js?body=1:10104:7)
at http://localhost:3000/assets/ember.js?body=1:18381:7 ember.js?body=1:3522
Uncaught Error: Assertion Failed: TypeError: undefined is not a function ember.js?body=1:74
这是我的应用程序到目前为止的样子 -
// http://emberjs.com/guides/models/using-the-store/
Blog.Store = DS.Store.extend({
adapter: 'Blog.ApplicationAdapter'
});
Blog.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
})
// For more information see: http://emberjs.com/guides/routing/
Blog.Router.map(function() {
this.resource('posts');
});
#posts.handlebars
<h1>Entries...</h1>
{{#each post in controller}}
{{render "post" post}}
{{/each}}
#post.handlebars
<h2>{{title}}</h2>
Blog.PostsRoute = Ember.Route.extend({
model: function() {
return this.get('store').findAll('Post')
}
})
Blog.Post = DS.Model.extend({});
我该怎么做呢?
答案 0 :(得分:0)
而不是:
Blog.PostsRoute = Ember.Route.extend({
model: function() {
return this.get('store').findAll('Post')
}
})
我写道:
Blog.PostsRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('post')
}
})