且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们如何在 ember 的 action 中获取原始事件

更新时间:2022-11-11 09:21:13

未使用操作助手传递事件.如果你真的想要事件对象,你需要定义一个视图并使用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);              
}