emberjs 动作 event.target 未定义 [英] emberjs action event.target is undefined

查看:27
本文介绍了emberjs 动作 event.target 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个 jsfiddle 的链接:http://jsfiddle.net/Qt972/

Here's a link to a jsfiddle: http://jsfiddle.net/Qt972/

当你运行 fiddle 时,你会看到一个名字和一个按钮,让人"打招呼.这工作正常,但是事件"未定义.

When you run the fiddle you'll see a name and a button to make the "person" say hello. This works fine, however the "event" is undefined.

一个更简单的案例也失败了:

An even simpeler case also fails:

http://jsfiddle.net/CCg2K/1/

有谁知道我该如何解决这个问题?

Does anyone know how I can fix this issue?

推荐答案

当您在操作回调中执行 console.log(arguments) 时,您可以看到实际上传递了 3 个参数.第一个是视图,第二个是事件,第三个是上下文.

When you do a console.log(arguments) inside your action callback you can see that there are actually 3 parameters passed. The first one is the view, the second is the event and the third is the context.

您可以像这样重写您的编辑操作:

You can rewrite your edit action like this:

edit: function(view, event, context) {
  var target = event.target;
  ...
}

<小时>

UPDATE:自提交 657a2664 - 在 版本中可用0.9.6 我猜 - 只传递了一个 event 参数,它具有视图和上下文作为属性.因此,如果您想访问那些,您必须执行以下操作:


UPDATE: since commit 657a2664 - available in release 0.9.6 I guess - only a single event parameter is passed which has the view and context as properties. So if you want to access those you have to do the following:

edit: function(event) {
  var view = event.view;
  var context = event.context;
  ...
}

这篇关于emberjs 动作 event.target 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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