dagda1
dagda1

Reputation: 28770

ember.js - target route action instead of controller when itemcontroller specifiec

I am iterating over a collecion using an itemController like this:

{{#each col itemController="colItem"}}
  <li>
    <a {{action doAction this}} href="#">{{name}}</a>
  </li>
{{/each}}

I want doAction to go to the route and not the itemController.

I have doAction defined in a route like this:

Radium.SomeRoute = Ember.Route.extend
  events:
    doAction: (status)->

If I remove the itemController then it will be dispatched to the route. Can I target the route action somehow?

Upvotes: 0

Views: 1046

Answers (1)

Mike Grassotti
Mike Grassotti

Reputation: 19050

Assuming your controller is an instance of Ember.Controller and has not implemented it's own doAction, the event should automagically bubble up to the route.

It may be an ember bug, but it seems that events do not bubble to the router when you specify an item controller via the {{#each}} helper.

As a workaround, you can instead specify the itemController as a property of the parent controller.

App.ItemsController = Ember.ArrayController.extend({
  itemController: "Item"
});

I've created a jsbin to demonstrate this workaround: http://jsbin.com/anesop/2/edit

Upvotes: 2

Related Questions