1
votes

I am trying to follow the "Ember Application Architecture" guide from teh Ember.js docs in order to make a simpla app with outlets and routing, but something keps buzzing me all the time.

Why does the ember router set a controller as the data context for a template, and not a view object? This screws up everything. For example, if the following template has to be rendered and attached to an outlet as a result of a URL change:

<script data-template-name="feed_template" type="text/x-handlebars">
    <h1>The feeds<h1>
    {{this}}
    {{#each items}}
      <a href="#" {{action "onClick"}}>test</a>
    {{/each}}
  </script>

The data context of the template is a controller, and not a view object. That is still somewhat OK, however, now none of the {{action}} interactions seem to work, becuase, guess what, the context is different ...

So what do I do?

1

1 Answers

1
votes

The context of actions has been changed to the router as of ember-1.0.pre release. So your onClick action will be handled by the router by default. To change it to the view, you have to explicitly set the target on the action or set the controller.target property. To set the view as the target of the action:

<script data-template-name="feed_template" type="text/x-handlebars">
    <h1>The feeds<h1>
    {{this}}
    {{#each items}}
      <a href="#" {{action onClick target="view"}}>test</a>
    {{/each}}
</script>