1

I know the sendAction will send actions from a component to the controller associated with the template where it has been placed, but in my case the component is not placed directly inside a route's template. Instead, my component is inside a view's template:

<script type="text/x-handlebars" data-template-name="displayTemplate">
    <h3>View</h3>

    ...

    {{componentA}}

</script>

This component has a controller associated with it:

App.ComponentAController = Ember.Controller.extend({
    ...
}

But the wrapping view does not, it's just a view:

App.DisplayView = Ember.View.extend({
    templateName: 'displayTemplate',

    actions: {
         updateData: function(data) {
             /* how can I get this triggered when an action happens in the embedded componentA? I'd like to 
             process the data object here so I can update the wrapping view accordingly. */
         }
    }
...
}

If I implement the action in the component's controller, it is not triggered when I perform a sendAction('updateData', data) from within the component. If I implement that in DisplayView, it is not triggered either.

So the question is: when an action is triggered in componentA, how can I send that action to the view DisplayView for handling?

More specifically, I'm trying to send context data to that view so it can be updated depending on what is selected on the embedded component. So if there is another way of communicating this data that'd work too. I chose actions just because it seemed appropriate, but maybe it is not.

UPDATE: The actual scenario

The actual code refers to a grid view, which in it's template has a pagination component. When the user switches to a new page, the pagination component sends a request to the server for the selected page.

Once data is returned, it then needs to let the wrapping view (which contains the grid) know that new data is available. When the user clicks on the page number, the action is handled in the pagination component and that's why I make the data call from there. If I needed to paginate something else, I wanted to reuse this component so I didn't want to make the pagination part of the grid view.

Edy Bourne
  • 5,679
  • 13
  • 53
  • 101
  • is there any reason you don't move the action from the view to the associated controller? – Kingpin2k Jun 03 '14 at 00:44
  • Yeah.. that action will have data attached to it that I need to update the view. If I move it to the view's controller, then the controller will have to know about the view which is a bad thing. I'd like to keep the controller knowing nothing about the view if possible. But I also tried that, and when I invoked `sendAction('updateData', data)` from the component the method on the view's controller never gets invoked. Not sure why. I had associated the view with the controller using `controller: App.DisplayController.create()` on the view. I'd prefer to keep the UI updates in the view, though. – Edy Bourne Jun 03 '14 at 00:52
  • What kind of ui updates are you doing? – Kingpin2k Jun 03 '14 at 02:41
  • Data binding generally happens at the controller level, and manually updating data from the view sounds like an anti-pattern, but I'm not sure what you're updating yet. – Kingpin2k Jun 03 '14 at 04:12
  • @kingpin2k I have updated the question to include the actual scenario I'm trying to accomplish. Please let me know your thoughts. Thanks! – Edy Bourne Jun 03 '14 at 14:28

1 Answers1

2

Normally you pass target, but the context of a component the property name is targetObject.

{{foo-bar action='actionName' targetObject=view}}

jasonmit
  • 1,268
  • 8
  • 8
  • thanks for that! took me hours to find... some additional information: to target the itemController in an `#each` we can do: `{{#echo posts itemController="post" as |p|}} .... {{foo-bar action='actionName' targetObject=p }} .... {{/each}}` – Jeff Jul 25 '15 at 18:04