Ember template chaining

我只是一个虾纸丫 提交于 2019-12-24 10:45:34

问题


I have this HTML/Handlebars code, what I would like is for the "outlet fav" to render the template with id "fav" and its corresponding outlet/templates-chain with expected "index". Kinda like displaying a different Ember URL as a part of the index. Is it possible natively(Without supplementing an iframe, which I think is a bad idea)? would it be considered a good practice(I know using views might help but just wondering if it is ok to walk this road)?

<script type="text/x-handlebars" id="application">
    Here we have our application
    {{outlet}}
</script>

<script type="text/x-handlebars" id="index">
    Application's First Child
    {{outlet}}
</script>

<script type="text/x-handlebars" id="index/index">
    Your Favourites
    {{outlet fav}}
</script>

<script type="text/x-handlebars" id="fav">
    {{#link-to 'fav'}}All{{/link-to}}       <!-- Link A-->
    {{#link-to 'fav.top'}}Top{{/link-to}}   <!-- Link B-->

    <!-- Expected Output from "fav/index" -->
    {{outlet}}
</script>

<script type="text/x-handlebars" id="fav/index">
     All Favourites Content
</script>

<script type="text/x-handlebars" id="fav/top">
    Top Favourites Content
</script>

<script type="text/x-handlebars" id="football">
    Football Content
</script>

JS Code: Here's what I tried

App.Router.map(function(){
    this.resource('index', {path: '/'}, function(){
        this.resource('fav', function(){
            this.route('top');
            this.route('last');
        });
    });
    this.route('football');
});
App.IndexIndexRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render();
        this.render("fav", {into: 'index'});
    }
});
Output:
===================================
Here we have our application
Application's First Child
Your Favourites
Link A
Link B
===================================

Omits the child outlet which should display content from "fav/index"

Help Appreciated.

回答1:


You can add an additional render call in IndexIndexRoute,

App.IndexIndexRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render();
        this.render("fav", {into: 'index'});
        this.render("fav/index", {into: 'fav'});
    }
});

http://jsfiddle.net/7b8HT/

Also, you may certainly use views as well to achieve similar results.



来源:https://stackoverflow.com/questions/19247615/ember-template-chaining

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!