我的错误
GET http://localhost:63342/people 404 (Not Found)
和
Assertion failed: Error while loading route:....
为什么会出现此错误http://localhost:63342/people 404
?我没有这条路。
这是我的js代码:
window.Models = Ember.Application.create();
Models.Router.map(function () {
//匹配路由后显示person_list模板
this.resource('persons', { path: '/' });
});
Models.PersonsRoute = Ember.Route.extend({
model:function(){
return this.store.find('person');
},
setupController:function(controller, model){
controller.set('content', model)
}
});
Models.Person = DS.Model.extend({
name: DS.attr('string'),
description:DS.attr('string')
});
Models.Person.FEATURES = [{
name:'Kratos Zhang',
description:'a c# coder in 7agree.'
}]
和模板
<script type="text/x-handlebars" data-template-name="persons">
<ul>
{{#each item in persons}}
<li>
<h4>{{item.name}}</h4>
<p>{{item.description}}</p>
</li>
{{/each}}
</ul>
为什么不工作?
答案 0 :(得分:1)
如果不是您的端点,您可以覆盖适配器中的pathForType,默认情况下Ember数据将端点复数
App.ApplicationAdapter = DS.RESTAdapter.extend({
pathForType: function(type) {
//return Ember.String.pluralize(type);
return type;
},
});
这不是必需的,您可以将其删除
setupController:function(controller, model){
controller.set('content', model)
}
模板中不存在人
{{#each item in model}}
<li>
<h4>{{item.name}}</h4>
<p>{{item.description}}</p>
</li>
{{/each}}
或
{{#each item in controller}}
<li>
<h4>{{item.name}}</h4>
<p>{{item.description}}</p>
</li>
{{/each}}