在路由器中,我有一個事件'removeComment'。在控制器中,如果通過訪問this.get('target')。send('removeComment',context);,我得到錯誤沒有處理事件'removeComment'。當我使用this.get('target.router')。send('removeComment',comment),錯誤變爲對象#沒有方法'發送'。使用this.router.send('removeComment',comment),將給出錯誤:無法讀取屬性'發送'未定義的。emberjs-RC2-如何從控制器和操作訪問路由器實例不冒泡到路由器
也只是發送到'PostComitController'行動到PostEditController不會通過控制器泡沫,直到路線。
如何從emberjs rc2和routerV2中的控制器訪問路由器實例。
路由器:
EmBlog.Router.map(function() {
this.resource("posts", {path: '/posts'}, function(){
this.route('new');
this.resource('post', {path: '/:post_id/'}, function(){
this.route('edit', {path: '/edit'});
this.route('comments', {path: '/comments'});
this.route('newComment');
this.route('comment', {path: '/comments/:comment_id'});
this.route('editComment', {path: '/comments/:comment_id/edit'});
});
});
});
控制器
EmBlog.PostEditCommentController = Ember.ObjectController.extend({
destroyMe: function(comment) {
this.get('target.router').send('removeComment', comment);
}
});
路由器
EmBlog.PostEditCommentRoute = Ember.Route.extend({
events: {
removeComment: function(context) {
var comment = context.get('content');
comment.deleteRecord();
comment.get('store').commit();
this.transitionTo('post.index');
}
}
});
我在帖子/評論模板中訪問它。這是該模板的控制器。
EmBlog.PostCommentsController = Ember.ArrayController.extend({
needs: ['postEditComment']
});
的崗位/評論模板
<script type="text/x-handlebars" data-template-name="post/comments">
{{#each controller}}
<p><a href='#' {{action destroyMe this target="controller.controllers.postEditComment"}}> Destroy </a></p>
{{/each}}
</script>
請問您可以添加路由圖嗎?我認爲this.get('target')。發送('removeComment',context)'應該可以工作,但我懷疑這是發送到其他路由。 –
感謝您的時間。我在問題的頂部添加了路由器,並決定添加** [jsfiddle](http://jsfiddle.net/VrR2T/6/)**。 – brg