路由的另一个重要职责是渲染同名字的模板。
比如下面的路由设置,posts路由渲染模板posts.hbs,路由new渲染模板posts/new.hbs。
Router.map(function() {this.route('posts', function() {this.route('new');});});
每一个模板都会渲染到父模板的{{outlet}}上。比如上面的路由设置模板posts.hbs会渲染到模板application.hbs的{{outlet}}上。application.hbs是所有自定义模板的父模板。模板posts/new.hbs会渲染到模板posts.hbs的{{outlet}}上。
如果你想渲染到另外一个模板上也是允许的,但是要在路由中重写renderTemplate回调方法。
// app/routes/posts.jsimport Ember from 'ember';export default Ember.Route.extend({// 渲染到favorites模板上renderTemplate: function() {this.render('favorites');}});
模板的渲染这个知识点比较简单,内容也很少,在前面的 路由、模板的执行、渲染顺序 已经介绍过相关的内容。
转载本站内容时,请务必注明来自W3xue,违者必究。


优化或报错有奖
皖公网安备34020702000426号