Ember: Error with named outlets

折月煮酒 提交于 2019-12-06 05:05:16

The problem is that you're not rendering the posts template. You can fix this by adding this.render() or this._super() before you define the templates of the outlets of the route you are in get rendered:

App.PostsRoute = Ember.Route.extend({
    renderTemplate: function() {

        // add this line
        this._super();

        this.render('sidebarTemplate', {
            into: 'posts',
            outlet: 'sidebar'
        });
        this.render('contentTemplate', {
            into: 'posts',
            outlet: 'content'
        });
    }
});

Just one note on extending features; In this particular code, the call this._super() would technically be the same as calling this.render(), but the difference is that by calling _super() you are extending the renderTemplate functionality by appending your stuff to what the method would do on its own, which in this case would be call this.render() and perhaps another routine this method might need to perform (generally speaking, not exclusive to renderTemplate), while if you call the method that does the thing you want yourself, in this case the render method, you'll be excluding from the flow the other things that this method could perform. And this is not right or wrong. It really depends on what you want to achieve. For most cases you should call this._super() instead of re-writing the implementation again in the event that the method you're extending does more than one thing and/or gets to do more than one thing in the future.

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