繁体   English   中英

Ember.js帮助进行路由器映射

[英]Ember.js help for router map

我想获取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

好的,首先,您可以从{ 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回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM