我是 ember 新手,正在尝试使用固定装置显示一些帖子的标题,但由于某种原因没有显示任何数据。当我将 Handlebars 脚本标记添加到我的 html 文件时,根本没有显示任何内容。
我有一个帖子模型
Blog.Post = DS.Model.extend({
title: DS.attr('string'),
link: DS.attr('string')
});
Blog.Post.FIXTURES = [
{
id: 0,
title: 'first post',
link: 'www.google.com'
},
{
id: 1,
title: 'second post',
link: 'www.reddit.com'
},
{
id: 2,
title: 'third post',
link: 'www.wikipedia.com'
}
];
在我的 application.js 中
Blog.ApplicationAdapter = DS.FixtureAdapter.extend();
在我的路由器中
Blog.PostsRoute = Ember.Route.extend({
model: function() {
return this.store.find('post');
}
});
在我的index.html 文件中
<script type="text/x-handlebars" data-template-name="post">
<ul>
{{#each}}
<li>
{{title}}
</li>
{{/each}}
</ul>
</script>
任何帮助都会非常感谢。
最佳答案
您缺少应用程序模板,它是应用程序的根目录。此外,您的路线名为 Posts(复数),但您的模板名为 post
(单数)。
此外,我在所述路由器中没有看到路由器和 posts
资源。在这里你会看到我把它们全部变成了复数。
Blog.Router.map(function() {
this.resource('posts');
});
Blog.PostsRoute = Ember.Route.extend({
model: function() {
return this.store.find('post');
}
});
<script type="text/x-handlebars" data-template-name="posts">
<h3>Post</h3>
<ul>
{{#each}}
<li>
{{title}}
</li>
{{/each}}
</ul>
</script>
关于javascript - 使用夹具适配器不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23796822/