问题
I have a view triggers an event which is handled inside the router state.
<button {{action signUp this}} type="button" class="btn btn-primary">Sign-Up</button>
here is a handler:
signUp: (router, event) ->
//how do I get an instance of the "View" class triggered an event?
I can use event.context to get all bound properties of the View class, but in fact I want to get a complete instance of the View class which has triggered the event. Any hints how to achieve this?
回答1:
If you want to do validations etc. in the view, I'd recommend to call the action on the view
// template
{{action signUp target="parentView"}}
and there send the event to the router via
// view
signUp: function() {
// validation etc
App.router.send('signUp',context);
}
You could manipulate your context to contain a reference to the current view (this
) as well if you need to.
Hope that helped!
来源:https://stackoverflow.com/questions/11865099/ember-js-get-view-triggering-event-in-the-router