我们如何在ember的动作中获得原始事件 [英] How can we get the orginal event in ember's action

查看:95
本文介绍了我们如何在ember的动作中获得原始事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新一个个人项目,我使用了ember.js版本0.9.x。



所以一个新版本被发布,我有一个与ember action。



我有以下html代码:

  ; li>< a href =#id =startApp{{action activateView target =view}}>家庭及LT; / A> < span class =divider> |< / span>< / li> 

其中,当我单击其调用此功能activateView:

  activateView:function(event,context){
console.log(event);
}

但事件和上下文未定义。我有alredy尝试过this.context,它返回未定义。



主要的想法是获取用户点击链接的ID。



我知道路线和手柄帮助链接,但我真的需要其他东西的id,



你能帮助我吗? / p>

感谢

解决方案

事件没有使用action helper传递。如果你真的想要事件对象,你需要定义一个视图并使用点击事件:

  App.MyLink = Em.View.extend({
click:function(e){
}
});

然后:

 < li> {{view App.MyLink}}< / li> 

但是要求访问dom事件是一种罕见的情况,因为您可以将参数传递给 {{动作}} 。在你的情况下:

 < li>< a href =#id =startApp{{action activateView startApptarget =view}}>家庭及LT; / A> < span class =divider> |< / span>< / li> 

,事件如下:

  activateView:function(id){
console.log(id);
}


I'm updating a personal project where I used the ember.js version 0.9.x.

So a new version was released and I have a problem related with ember action.

I have the following html code:

<li><a href="#" id="startApp" {{action activateView target="view"}}> Home</a> <span class="divider">|</span></li>

where, when I click its call this function activateView:

activateView: function(event, context) {
   console.log(event);              
}

but the event and the context are undefined. I've alredy tried this.context and it returns undefined.

The main idea its obtain the id of the link when the user click.

I know about routes and the handlebar helper link to, but I really need that id for other things,

Can you help me?

Thanks

解决方案

The event is not passed using the action helper. If you really want the event object, you need to define a view and use the click event:

App.MyLink = Em.View.extend({
  click: function(e) {
  }
});

and then:

<li>{{view App.MyLink}}</li>

but requiring access to the dom event is a rare case, because you can pass arguments to {{action}}. In your case:

<li><a href="#" id="startApp" {{action activateView "startApp" target="view"}}> Home</a> <span class="divider">|</span></li>

and in the event:

activateView: function(id) {
  console.log(id);              
}

这篇关于我们如何在ember的动作中获得原始事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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