简体   繁体   English

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

[英]Ember.js help for router map

I want get URL: localhost#/234/23/456/524jk53 (/one_id/two_id/three_id/four_id) 我想获取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'});
                });
            });
        });
});

and separation of templates: 和模板分离:

 <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>

route: 路线:

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

i have error: assertion failed: Cannot call get with 'id' on an undefined object. 我有错误:断言失败:无法在未定义的对象上调用带有'id'的get。

Please, help me write router.map for this application's hierarchy 请帮我为该应用程序的层次结构编写router.map

Okay, so first up, you can remove the / from { path: '/:dynamic_id' } . 好的,首先,您可以从{ path: '/:dynamic_id' }删除/

Next, you need to understand that when a dynamic segment is expected within the route you are referencing in your linkTo helper, you need to pass model (or other) objects as additional parameters to the linkTo helper as context for each dynamic segment. 接下来,您需要了解,当要在linkTo帮助器中引用的路由中预期有动态分段时,您需要将模型(或其他)对象作为附加参数传递给linkTo帮助器,作为每个动态分段的上下文。

This is probably why you're getting the error. 这可能是您收到错误的原因。 Your router should look something like this: 您的路由器应如下所示:

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'});
                });
            });
        });
});

And in your template, you should be passing context for the segments, so for instance: 在模板中,您应该传递段的上下文,例如:

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

Anyway, I think that you need to refine your question some what. 无论如何,我认为您需要对问题进行一些改进。 What exactly are you trying to achieve? 您到底想达到什么目的? If your dynamic segments aren't model IDs, then you might need to look at overriding the serialize callback in the relevant route files. 如果动态段不是模型ID,则可能需要查看覆盖相关路由文件中的serialize回调。

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

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