1
這個簡單的Ember應用程序應該列出帖子。但Ember不呈現帖子模板。爲什麼Ember不呈現子資源?
JS:
App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.Router.map(function() {
this.resource('posts', function(){
this.resource('post', { path: '/:post_id'});
});
});
App.Post = DS.Model.extend({
title: DS.attr('string')
});
App.Post.FIXTURES = [
{ id: 1, title: "First post" },
{ id: 2, title: "Second post" },
{ id: 3, title: "Last post" },
];
App.PostsRoute = Ember.Route.extend({
model: function() {
return this.store.find('post');
}
});
HTML體標記:
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
{{#link-to 'posts'}}
posts
{{/link-to}}
</script>
<script type="text/x-handlebars" data-template-name="posts">
<h3>Posts list</h3>
<ul>
{{#each post in model}}
<li>
{{#link-to 'post' post}}
{{post.title}}
{{/link-to}}
</li>
{{/each}}
</ul>
</script>
<script type="text/x-handlebars" data-template-name="post">
Post #{{id}}: {{title}}
</script>
</body>
本實施例的JSBin。
注:如果我刪除posts
模板和訪問/#/posts/1
URL,灰燼呈現post
模板。
這段代碼有什麼問題?
看http://stackoverflow.com/questions/25817621/emberjs -complex路由/ 25823132#25823 132,情況可能如此。 – Microfed 2014-10-03 21:31:36