2013-07-25 38 views
1

在我的用例中,我想從父路線導航到子路線,從子導航到父項。第一個案件工作,但第二個案件沒有。爲什麼?哪裏不對? renderTemplate中的錯誤?從孩子導航到父母不工作

App = Ember.Application.create(); 

App.Router.map(function() { 

    this.resource('parent',function(){ 
     this.resource('child',function(){ 
    }); 
    }); 

}); 

App.ChildRoute = Ember.Route.extend({ 

    renderTemplate: function(){ 
    this.render('child', { 
     into: 'application', 
     controller: 'child' 
    }); 
    } 
}); 


<script type="text/x-handlebars"> 
    <h1>Ember Sandbox</h1> 

    <nav> 
    {{#linkTo 'parent'}} Parent {{/linkTo}} 
    </nav> 

    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="index"> 
    <h2>Welcome</h2> 
</script> 

<script type="text/x-handlebars" data-template-name="parent"> 
    <h2>Parent</h2> 
    {{#linkTo 'child'}} Child {{/linkTo}} 

</script> 

<script type="text/x-handlebars" data-template-name="child"> 
    <h2>Child</h2> 
    {{#linkTo 'parent'}} Parent {{/linkTo}} 
</script> 

回答

3

每當您嵌套資源時,emberjs都會提供一個Index路由(App.ParentIndexRoute)。當您從子資源轉換到父級時,父級模板已經被渲染,因此它將被重定向到索引路由(App.ParentIndexRoute)。

渲染在App.ParentIndexRoute父模板將解決您的問題

App.ParentIndexRoute = Ember.Route.extend({ 
renderTemplate: function(){ 
    this.render('parent', {into: 'application'}); 
} 
}); 

Your Working jsbin