Ember.js在路由器中获取视图触发事件 [英] Ember.js get view triggering event in the router

查看:55
本文介绍了Ember.js在路由器中获取视图触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图触发在路由器状态内部处理的事件。

 < button {{action signUp this }} type = button class = btn btn-primary>注册< / button> 

以下是处理程序:

  signUp :(路由器,事件)-> 
//如何获取触发事件的 View类实例?

我可以使用event.context获取View类的所有绑定属性,但实际上我想要获取触发事件的View类的完整实例。

解决方案

如果要在视图中进行验证等,我建议致电视图上的操作

  //模板
{{action signUp target = parentView}}

然后通过



<$ p将事件发送到路由器$ p> //查看
signUp:function(){
//验证等
App.router.send('signUp',context);
}

您可以操纵上下文以包含对当前视图的引用(),如果需要的话。



希望有帮助!


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?

解决方案

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!

这篇关于Ember.js在路由器中获取视图触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆