【发布时间】:2014-09-07 17:19:36
【问题描述】:
当谈到模型 (http://emberjs.com/guides/templates/rendering-with-helpers/) 时,我不明白 Ember {{render}} 的解释。什么是“对应控制器的单例实例”?
When no model is provided it gets the singleton instance of the corresponding controller
When a model is provided it gets a unique instance of the corresponding controller
我正在尝试在页面上嵌入视图。我有一个帖子页面,我想在帖子页面中嵌入评论/新建,以便我可以在帖子页面上发表评论。
我可以去 cmets/new 并添加一条新评论。但是当我尝试使用 {{render}} 嵌入帖子页面时,它会出现错误,因为它不包含 CommentsNewRoute 逻辑。
问题是我在 CommentsNewRoute 中有逻辑,但是当我使用 {{render}} 时,它似乎忽略了路由逻辑。如何让{{render}} 只使用对应的Route 逻辑?
CommentsNewRoute:
App.CommentsNewRoute = Ember.Route.extend({
model: function(){
return this.store.createRecord('comment');
},
actions: {
willTransition: function(transition) {
if (this.currentModel.get('isNew')) {
this.get('currentModel').deleteRecord();
};
}
}
});
CommentsNewController:
App.CommentsNewController = Ember.ObjectController.extend({
actions: {
save: function() {
// do save new comment stuff
}
}
});
发布/索引 .hbs 模板:
<h1 class="page-header">Post {{id}}</h1>
{{render "comments/new"}} <<<<<< I want to embed the whole Comments/New page here, including the logic from CommentsNewRoute
路由器:
this.resource('post', { path: '/posts/:id' }, function() {
this.route('edit');
});
this.resource('comments', { path: '/comments' }, function() {
this.route('new');
});
版本:
DEBUG: ------------------------------- ember.js
DEBUG: Ember : 1.6.0-beta.5 ember.js
DEBUG: Ember Data : 1.0.0-beta.8.2a68c63a ember.js
DEBUG: Handlebars : 1.3.0 ember.js
DEBUG: jQuery : 1.11.1 ember.js
DEBUG: -------------------------------
【问题讨论】:
标签: ember.js ember-data