我有一个ember应用程序,我的路由看起来像这样:
App.Router.map(function() {
this.resource('works', {path: '/works'}, function(){
this.route('work', {path:':work_id'})
});
});
我希望能够在我的索引模板中链接我的每个工作,以进行导航。我试过这个,但它不起作用:
<script type="text/x-handlebars" data-template-name='application'>
<header id="header">
<nav id="main-nav" role="navigation">
<div class="item-container">
{{#link-to 'works' tagName='div' classNames="navItem work" }}
<p>Works</p>
{{/link-to}}
<ul>
{{#link-to 'work' works work}}{{work.title}}{{/link-to}}
</ul>
</div>
</nav>
</header>
<main id="main">
{{outlet}}
</main>
</script>
如果您需要更多信息,请告诉我。
答案 0 :(得分:0)
链接到路线时,请执行resource.route
{{#link-to 'works.work' work}}{{work.title}}{{/link-to}}
在这种情况下,我假设工作是一个模型的属性,如果没有,你需要显示你的路由器。
答案 1 :(得分:0)
您的索引路径定义应如下所示(假设您使用的是Ember数据):
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.find('work');
}
});
然后在您的index
模板中,浏览{{each}}
条记录的App.Work
并链接到works.work
路线:
<ul>
{{#each}}
<li>{{#link-to 'works.work' this}}{{title}}{{/link-to}}</li>
{{/each}}
</ul>