Ember.js get view triggering event in the router

青春壹個敷衍的年華 提交于 2019-12-24 20:42:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!