我为我的Ember应用程序设置了以下脚手架。
window.App = Ember.Application.create({});
App.Router.map(function () {
this.resource('coaches', function() {
this.resource('coach', {path: "/:person_id"});
});
});
App.ApplicationAdapter = DS.FixtureAdapter.extend({});
App.Person = DS.Model.extend({
fname: DS.attr('string')
,lname: DS.attr('string')
,sport: DS.attr('string')
,bio: DS.attr('string')
,coach: DS.attr('boolean')
,athlete: DS.attr('boolean')
});
App.Person.FIXTURES = [
{
id: 10
,fname: 'Jonny'
,lname: 'Batman'
,sport: 'Couch Luge'
,bio: 'Blah, blah, blah'
,coach: true
,athlete: true
}
,{
id: 11
,fname: 'Jimmy'
,lname: 'Falcon'
,sport: 'Cycling'
,bio: 'Yada, yada, yada'
,coach: false
,athlete: true
}
];
我正在尝试设置过滤人员模型并仅返回教练的路线。为了确保我可以访问数据,我只是在人物模型上使用了findAll。
App.CoachesRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('person');
}
});
现在,我正在尝试实施Ember.js Models - FAQ页面底部详细说明的过滤方法。
App.CoachesRoute = Ember.Route.extend({
model: function() {
var store = this.store;
return store.filter('coaches', { coach: true }, function(coaches) {
return coaches.get('isCoach');
});
}
});
教练路线根本没有实施新路线并且旧路线已经注释掉了。我使用的是Ember Chrome扩展程序,当使用过滤器路径时,控制台会使用Error while loading route: Error: No model was found for 'coaches'
进行响应。显然路线不起作用,特别是模型。不开玩笑吧?我的滤镜模型路线中缺少什么?
提前感谢您的帮助。
答案 0 :(得分:0)
错误消息是现货 - 没有CoachModel
。我想你需要这样做:
App.CoachesRoute = Ember.Route.extend({
model: function() {
var store = this.store;
return store.filter('person', { coach: true }, function(coaches) {
return coaches.get('isCoach');
});
}
});