【问题标题】:Template associated with nested route not rendering in parent template与嵌套路由关联的模板未在父模板中呈现
【发布时间】:2013-04-08 15:30:59
【问题描述】:

这是我的 HTML 模板:

<script type="text/x-handlebars">
    <p>Application template</p>
    {{#linkTo employees}}<button>Show employees</button>{{/linkTo}}
    {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name="employees">
    <p>Employees template</p>
    {{#linkTo employees.employee}}<button>Show employee</button>{{/linkTo}}
    {{outlet employeeOutlet}}
</script>

<script type="text/x-handlebars" data-template-name="employee">
    <p>Employee template</p>
</script>

这里是javascript:

App = Ember.Application.create();

App.Router.map(function () {
    this.resource('employees', function () {
        this.route('employee');
    });
});

App.EmployeeRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render('employee', {       // the template to render
            into: 'employees',          // the template to render into
            outlet: 'employeeOutlet',   // the name of the outlet in that template
            controller: 'employee'      // the controller to use for the template
        });
    }
});

JS斌here

我添加了很多不必要的代码,以尝试让员工模板在员工模板的出口中呈现(例如,命名出口,定义 renderTemplate 方法......),但似乎没有去工作。

我在这里做错了什么?

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    您需要将员工模板命名为 employees/employee ,它将起作用。否则你需要告诉视图使用员工模板。

    示例 http://jsbin.com/ukajix/1/

    【讨论】:

    • 好的,谢谢。尽管我确实浏览了几次文档,但我不记得他们谈论这个的确切位置。我也觉得你需要以这种方式命名模板有点奇怪(即,包括路径)。毕竟,这些代码是可以重复使用的模板。
    • 这里是有关命名约定的文档的链接。 emberjs.com/guides/concepts/naming-conventions/#toc_nesting
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多