当我在我的ember应用程序上运行特定路径时,我在控制台中不断收到“未捕获的#error”消息。它似乎没有影响任何东西,但为什么会这样?我已将它隔离到一个{{#each}}语句,但看不出它有什么问题,代码看似完美无缺。以下是相关的片段:
的index.html:
<script type="text/x-handlebars" data-template-name="blog/index">
<h4>Recent Posts</h4>
<table class="table">
{{#each}}
<tr><td>
{{#link-to 'blog.post' this}}
<h4>{{title}} <small class="muted">by {{author}}</small><h4>
{{/link-to}}
</td></tr>
{{/each}}
</table>
</script>
App.js
var App = Ember.Application.create({
LOG_TRANSITIONS: true
});
App.ApplicationAdapter = DS.FixtureAdapter;
App.Router.map(function () {
this.resource('blog', { path: '/blog' }, function () {
this.route('post', { path: '/post/:post_id' });
});
});
App.BlogIndexRoute = Ember.Route.extend({
model: function () {
return this.store.find('post');
}
});
App.Post = DS.Model.extend({
title: DS.attr(),
author: DS.attr(),
date: DS.attr(),
excerpt: DS.attr(),
body: DS.attr()
});
App.Post.FIXTURES = [
{
id: '1',
title: 'Rails in Omakase',
author: 'd2h',
date: new Date('12-27-2012'),
excerpt: 'This is an excerpt',
body: 'This is my body!'
},
{
id: '2',
title: 'The Parley Letter',
author: 'd2h',
date: new Date('12-24-2012'),
excerpt: 'This is an excerpt',
body: 'This is my body!'
}
];
就像我说的,如果我删除了{{#each}}语句,那么控制台中没有错误消息,但是如果我确实添加它,它就可以正常工作并给我这样的错误。我究竟做错了什么?
答案 0 :(得分:0)
您的表格缺少其<tbody>
代码
<table>
<tbody>
{{#each}}
<tr></tr>
{{/each}}
</tbody>
</table>
http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html