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