所以我仍然是Ember的初学者,现在我正试图从Ember-data中理解子类DS.Model。因此,出于某种原因,当我路由到帖子时,它会出现以下错误:
处理路径时出错:posts undefined不是函数TypeError:undefined不是函数
App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 12,
//where do we have to look for those records?
adapter: 'DS.FixtureAdapter'
});
App.Router.map(function() {
this.resource('posts');
this.resource('about');
});
App.PostsRoute = Ember.Route.extend({
//we're returning all the data that our application knows about
model: function() {
return App.Post.find();
}
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
intro: DS.attr('string'),
extended: DS.attr('string'),
publishedAt: DS.attr('date')
});
App.Post.FIXTURES = [{
id: '1',
title: "Rails is Omakase",
author: "d2h" ,
date: new Date('12-27-2012'),
excerpt: "There are lots of à la carte software environments in this world. Places where in order to eat, you must first carefully look over the menu of options to order exactly what you want.",
body: "I want this for my ORM, I want that for my template language, and let's finish it off with this routing library. Of course, you're going to have to know what you want, and you'll rarely have your horizon expanded if you always order the same thing, but there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is omakase."
}, {
id: '2',
title: "The Parley Letter",
author: "d2h" ,
date: new Date('12-24-2012'),
excerpt: "My [appearance on the Ruby Rogues podcast](http://rubyrogues.com/056-rr-david-heinemeier-hansson/) recently came up for discussion again on the private Parley mailing list.",
body: "A long list of topics were raised and I took a time to ramble at large about all of them at once. Apologies for not taking the time to be more succinct, but at least each topic has a header so you can skip stuff you don't care about.\n\n### Maintainability\n\nIt's simply not true to say that I don't care about maintainability. I still work on the oldest Rails app in the world."
}];
答案 0 :(得分:0)
将来你应该发布错误的其余堆栈跟踪,并指出错误发生在哪一行。当我们不知道他们正在发生时,我们很难找到错误。
幸运的是,您的代码并不太复杂,我已经看到足够的Ember代码来猜测您在模型上调用旧方法。使用App.Post.find()
查找记录已经被弃用了很长一段时间(看起来它也被删除了)。您应该使用this.get('store').find('post')
代替。