Invoke Route From Controller in Emberjs

Emberjs official document doesn’t describe how to invoke route method/event from controller. Why we need this?
Some methods(like render,controllerFor) only exist in Route scope.

PostRoute
1
2
3
4
5
6
7
App.PostRoute = Ember.Route.extend({
  events: {
    showWarn: {
      this.render('warn', { "outlet": "msgView", "into": "post" })
    }
  }
});

Use this.get('target').send to trigger Route event.

PostController
1
2
3
4
5
6
7
8
9
10
App.PostController = Ember.Controller.extend({
  actions: {
    showMessage: {
      //some process here
      if (need_render) {
        this.get('target').send('showWarn');
      }
    }
  }
});

Comments