Ember-Data - 无法读取未定义的属性“find”

时间:2013-05-08 05:27:20

标签: ember.js ember-data

只是想设置一个小提琴来解决其他一些问题,我不能通过应该是一个简单的设置。

在旧版本的ember中,我可以使用find()访问Fixture数据: http://jsfiddle.net/jdcravens/Btum7/

App = Ember.Application.create();

App.Store = DS.Store.extend({
  revision: 11,
  adapter: "DS.FixtureAdapter"
});

App.Team = DS.Model.extend({
    name: DS.attr('string'),
    colors: DS.attr('string')
})

App.Team.FIXTURES = [{
    id: 1,
    name: 'Celtics',
    colors: 'Green, White'
}, {
    id: 2,
    name: 'Lakers',
    colors: 'Yellow, Black'
}, {
    id: 3,
    name: 'Bulls',
    colors: 'Red, Black'
}, {
    id: 4,
    name: 'Mavericks',
    colors: 'Blue, White'
}, {
    id: 5,
    name: 'Spurs',
    colors: 'Black, Grey, White'
}];

App.Router = Ember.Router.extend();
App.Router.map(function (match) {
  match("/").to("home");
});

App.HomeRoute = Ember.Route.extend({
    setupController: function (controller) {
        controller.set('content', App.Team.find());
    }
});

使用模板:

<script type="text/x-handlebars" data-template-name="home">
  <ul class="teams">
  {{#each team in content}}
    <li>{{team.name}}</li>
  {{/each}}
  </ul>    
</script>

但在所有最新的库中,我将App.Team视为未定义: http://jsfiddle.net/jdcravens/JTWjU/6/

App = Ember.Application.create({});

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

App.Team = DS.Model.extend({
    name: DS.attr('string'),
    colors: DS.attr('string')
});

App.Team.FIXTURES = [{
    id: 1,
    name: 'Celtics',
    colors: 'Green, White'
}, {
    id: 2,
    name: 'Lakers',
    colors: 'Yellow, Black'
}, {
    id: 3,
    name: 'Bulls',
    colors: 'Red, Black'
}, {
    id: 4,
    name: 'Mavericks',
    colors: 'Blue, White'
}, {
    id: 5,
    name: 'Spurs',
    colors: 'Black, Grey, White'
}];

App.Router.map(function () {
    this.resource("home", {path: "/"})
});

App.HomeRoute = Ember.Route.extend({
    setupController: function (controller) {
        console.log(App)
        controller.set('content', App.Team.find());
    }
});

我不知所措。

1 个答案:

答案 0 :(得分:3)

你的代码很好。您使用的是过时版本的Ember Data。

您可以在http://builds.emberjs.com.s3.amazonaws.com/ember-data-latest.js

获取最新的余烬数据

更新ember-data.js文件,它将起作用。