未捕获的TypeError:无法读取未定义的属性'find' - EMBER-Data

时间:2013-04-30 09:36:22

标签: ember.js ember-data

我收到此错误消息:

**Uncaught TypeError: Cannot read property 'find' of undefined (13:24:29:797 | error, javascript)** 
at  (public_html/js/libs/ember-data-latest.js:3771:17)
at App.PostsRoute.Ember.Route.extend.model (public_html/js/app.js:16:25)
at superWrapper (public_html/js/libs/ember-1.0.0-rc.3.js:1044:16)
at Ember.Route.Ember.Object.extend.deserialize (public_html/js/libs/ember-1.0.0-rc.3.js:24232:22)
at Router._paramsForHandler (public_html/js/libs/ember-1.0.0-rc.3.js:23204:34)
at doTransition (public_html/js/libs/ember-1.0.0-rc.3.js:23348:27)
at Router.transitionTo (public_html/js/libs/ember-1.0.0-rc.3.js:23105:9)
at doTransition (public_html/js/libs/ember-1.0.0-rc.3.js:23979:25)
at Ember.Router.Ember.Object.extend.transitionTo (public_html/js/libs/ember-1.0.0-rc.3.js:23842:5)
at Ember.LinkView.Ember.View.extend.click (public_html/js/libs/ember-1.0.0-rc.3.js:24899:29)
at Ember.CoreView.Ember.Object.extend.trigger (public_html/js/libs/ember-1.0.0-rc.3.js:14355:21)
at superWrapper (public_html/js/libs/ember-1.0.0-rc.3.js:1044:16)
at Ember.merge.handleEvent (public_html/js/libs/ember-1.0.0-rc.3.js:16907:19)
at Ember.View.Ember.CoreView.extend.handleEvent (public_html/js/libs/ember-1.0.0-rc.3.js:16393:30)
at  (public_html/js/libs/ember-1.0.0-rc.3.js:14113:19)
at  (public_html/js/libs/ember-1.0.0-rc.3.js:4504:19)
at Ember.handleErrors (public_html/js/libs/ember-1.0.0-rc.3.js:411:17)
at invoke (public_html/js/libs/ember-1.0.0-rc.3.js:4502:16)
at tryable (public_html/js/libs/ember-1.0.0-rc.3.js:4687:14)
at Ember.tryFinally (public_html/js/libs/ember-1.0.0-rc.3.js:1199:24)
at Ember.run (public_html/js/libs/ember-1.0.0-rc.3.js:4691:16)
at Ember.EventDispatcher.Ember.Object.extend._bubbleEvent (public_html/js/libs/ember-1.0.0-rc.3.js:14112:18)
at  (public_html/js/libs/ember-1.0.0-rc.3.js:14058:25)
at Ember.handleErrors (public_html/js/libs/ember-1.0.0-rc.3.js:411:17)
at  (public_html/js/libs/ember-1.0.0-rc.3.js:14049:20)
at jQuery.event.dispatch (public_html/js/libs/jquery-1.9.1.js:3074:9)
at elemData.handle (public_html/js/libs/jquery-1.9.1.js:2750:28)

这是我的app.js:

App = Ember.Application.create();

App.store = DS.Store.extend({
    revision: 12,
    adapter: 'DS.FixtureAdapter'
});

App.Router.map(function () {
    this.resource('posts');
    this.resource('about');
});

App.PostsRoute = Ember.Route.extend({
    model: function () {
        return App.Post.find();
    }
});

App.Post = DS.Model.extend({
    id: DS.attr('string'),
    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: "this is test post",
        author: "Ali",
        publishedAt: new Date('12-24-2012'),
        intro: " A quick brown fox jumps over the lazy dogs. contains all the English alpabet",
        extended: "Their must be some extension for other languages :P :P :P",
    }, {
        id: '2',
        title: "TEST Daily POST",
        author: "Naveed",
        publishedAt: new Date('03-24-2013'),
        intro: " our aims is to touch the new horizons",
        extended: "TESTING , TESTING TESTING",
    }, {
        id: '3',
        title: "TEST2 Daily POST",
        author: "SAJJAD",
        publishedAt: new Date('01-15-2013'),
        intro: " Do Nothing, Get Every thing",
        extended: "We provide an easy way to connect and do business with your customer. We are here to make your life easy.",
    }
];

1 个答案:

答案 0 :(得分:-1)

由于ember-data-latest.js和ember-1.0.0-rc.3.js版本存在差异,我遇到了同样的问题。

解决方案是使用github上的master分支从头开始构建ember.js / ember-data.js。

先决条件:

1 )构建ember.js

git clone https://github.com/emberjs/ember.js ember

cd ember && bundle install

rake dist

(编译后见“dist”目录)

2 )构建ember-data.js

git clone https://github.com/emberjs/data.git

cd data && bundle install

rake dist

我希望这有帮助!