簡體   English   中英

Ember.js:如何使子路線顯示在父資源中

[英]Ember.js: How to make children routes display in the parent resource

最近,我一直在閱讀余燼文檔,並盡力而為。 我已經取得了良好的進展,我感謝上帝,但是最近我在路由方面遇到了麻煩。 具體來說,我可以讓模板顯示在應用程序模板中,但是我不能讓子級路由顯示在父資源模板中。 相反,子模板實際上將其替換。 這是我的代碼:

的index.html

 <script type="text/x-handlebars" data-template-name="modals"> <h2>Modals Parent Route</h2> <p>This is the modals route which is common to all modals</p> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="modals/layout"> <h2>Layout Route</h2> </script> <script type="text/x-handlebars" data-template-name="modals/visuals"> <h2>Visuals Route</h2> </script> <script type="text/x-handlebars" data-template-name="modals/finish"> <h2>Finish Route</h2> </script> <script type="text/x-handlebars" data-template-name="modals/preview"> <h2>Preview Route</h2> </script> 

App.js

 App.Router.map(function(){ this.resource('modals', { path:'/modals' }, function(){ this.route('layout'); this.route('visuals'); this.route('finish'); this.route('preview'); }); }); App.LayoutRoute = Em.Route.extend({ renderTemplate: function() { this.render('modals.layout',{ into: 'modals', }); } 

這不是完整的代碼,但我認為這將是與該主題相關的全部。 請隨時問我是否需要完整的文件內容。

您正在使用的renderTemplate方法完全覆蓋了modals模板,這就是為什么要擺脫它。 Ember為您處理模板的呈現,而您要實現的基本功能則不需要它。

因此,我使用了ember-cli,並最終找到了一種使此工作正常進行的方法。 我使用ember-cli g路線生成了我的路線。 除申請外,我為每條路線都運行了一次。 之后,一切正常。 這是某人為我創建的git存儲庫,它將幫助遇到相同問題的任何人: https : //github.com/mooror/mooror 感謝大家

如果需要嵌套模板,則需要嵌套路由。

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

請參閱: http//guides.emberjs.com/v1.10.0/routing/defining-your-routes/#toc_nested-resources

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM