我们如何获得余烬行动中的原始事件 [英] How can we get the original event in ember's action

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

问题描述

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

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.

我有以下html代码:

I have the following html code:

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

其中,当我单击其调用时,此函数activateView:

where, when I click its call this function activateView:

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

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

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

主要思想是当用户单击时获取链接的ID。

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

我知道路线和到的车把帮助链接,但是我真的需要该ID做其他事情,

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

推荐答案

未使用动作帮助器传递事件。如果您确实想要事件对象,则需要定义一个视图并使用 click 事件:

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) {
  }
});

然后:

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

但是很少需要访问dom事件,因为您可以将参数传递给 {{action}} 。在您的情况下:

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>

,并且在以下情况下:

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

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

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