只是试图设置一个小提琴来解决其他一些问题,但我无法通过应该是一个简单的设置。
在旧版本的 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());
}
});
我不知所措。