我想添加一个资源(例如sites/5/posts/
-> posts 是我添加的新资源)。
WebApp.Router.map(function () {
this.resource('sites', { path: '/' } , function() {
this.resource('site', { path: '/sites/:site_id'} , function() {
this.resource('posts', { path: 'posts'
}); //posts
}); //sites/id
this.route('new', {path: 'new'});
});
});
我的模板:
<script type="text/x-handlebars" data-template-name="sites">
<ul>
{{#each site in controller}}
<li>
{{#linkTo 'site' this}} {{site.siteName}} {{/linkTo}}
{{#linkTo 'posts'}} > {{/linkTo}}
</li>
{{/each}}
</ul>
{{#linkTo 'sites.new'}} ADD NEW WEBSITE {{/linkTo}}
{{outlet}}
我希望每个列表项都有指向的链接sites/:site_id/posts/
。将行添加{{#linkTo 'posts'}} > {{/linkTo}}
到模板会产生错误:
Assertion failed: Cannot call get with 'id' on an undefined object.
我做错了什么?