How to access specific context in ember 1.0 pre using action helper

In my ember view, I want to get the person during this each and pass it into action, but currently I only get the jquery event in the router (curious if this is context bound for free in pre 1.0 now)

template

<script type="text/x-handlebars" data-template-name="person"> {{#each person in controller}} <li> {{person.username}} <input type="submit" value="delete" {{action removePerson person}}/> </li> {{/each}} </script> 

router w / method that I was hoping to call in the user context

 Router: Ember.Router.create({ root: Ember.Route.extend({ index: Em.Route.extend({ route: '/', removePerson: function(router, context) { router.get('personController').removePerson(context); }, 

in details

 PersonController: Ember.ArrayController.extend({ content: [], addPerson: function (username) { var person = PersonApp.Person.create({ username: username }); this.pushObject(person); }, removePerson: function (person) { this.removeObject(person); } }), 
+4
source share
1 answer

The second variable passed to the router action handler is actually an event. Context is a variable of this event. Rewrite it like this:

 Router: Ember.Router.create({ root: Ember.Route.extend({ index: Em.Route.extend({ route: '/', removePerson: function(router, event) { router.get('personController').removePerson(event.context); }, 
+5
source

All Articles