0

我想获取 URL:localhost#/234/23/456/524jk53 (/one_id/two_id/three_id/four_id)

Stat.Router.map(function () {
    this.resource('one', {path: '/:one_id'}, function(){
            this.resource('two', {path: '/:two_id'}, function(){
                this.resource('three', {path: '/:three_id'}, function () {
                    this.resource('four', {path: '/:four_id'});
                });
            });
        });
});

和模板分离:

 <script type="text/x-handlebars">
    {{outlet one}}<br>
    {{outlet two}}<br>
    {{outlet three}}<br>
    {{outlet}}
 </script>
<script type="text/x-handlebars" data-template-name="one">
  one, to {{linkTo 'two'}}two{{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="two">
  two, to {{linkTo 'three'}}three{{/linkTo}} 
</script>
<script type="text/x-handlebars" data-template-name="three">
  three, to {{linkTo 'four'}}four{{/linkTo}} 
</script>
<script type="text/x-handlebars" data-template-name="four">
  four
</script>

路线:

App.oneRoute = Em.Route.extend({
    renderTemplate: function() {
        this.render('two', {outlet: 'two'});
        this.render('three', {outlet: 'three'});
        this.render('four', {outlet: 'four'});
    }
});

我有错误:断言失败:无法在未定义的对象上调用带有 'id' 的 get。

请帮我为这个应用程序的层次结构编写 router.map

4

1 回答 1

1

好的,首先,您可以删除/from { path: '/:dynamic_id' }

接下来,您需要了解,当您在linkTo帮助程序中引用的路由中需要动态段时,您需要将模型(或其他)对象作为附加参数传递给 linkTo 帮助程序作为每个动态段的上下文。

这可能就是您收到错误的原因。您的路由器应如下所示:

Stat.Router.map(function () {
    this.resource('one', {path: ':one_id'}, function(){
            this.resource('two', {path: ':two_id'}, function(){
                this.resource('three', {path: ':three_id'}, function () {
                    this.resource('four', {path: ':four_id'});
                });
            });
        });
});

在您的模板中,您应该传递段的上下文,例如:

{{linkTo 'two' modelOne modelTwo}}Hello World!{{/linkTo}}

无论如何,我认为你需要改进你的问题。你到底想达到什么目的?如果您的动态段不是模型 ID,那么您可能需要查看覆盖serialize相关路由文件中的回调。

于 2013-08-16T13:12:43.303 回答