Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send actions to parent controllers?

Tags:

ember.js

I have an action that may be triggered from different routes/templates, but ultimately should be sent to an action in the application controller. How do I do this? I've only seen examples of the needs property being used for sending actions to child controllers.

So how can actions sent from /posts/post and / (application) both be sent to the application controller?

like image 878
Haz_ah Avatar asked May 21 '14 13:05

Haz_ah


1 Answers

You usually define the action handler in the ApplicationRoute as:

App.ApplicationRoute = Em.Route.extend({
  actions: {
    print: function() {
      console.log('hello');
    }
  }
});

Then, if your action is not defined either on your controller or specific route, the action will bubble up to any parent routes until the ApplicationRoute.

If you want to handle the action in your route and at the application level, you must return true in your action handler in order the action can bubble up.

App.IndexRoute = Em.Route.extend({
  actions: {
    print: function() {
      console.log('hello');
      return true;
    }
  }
});

Check the guide for a detailed description.

like image 175
ppcano Avatar answered Nov 10 '22 07:11

ppcano