emberjs action event.target未定义 [英] emberjs action event.target is undefined
问题描述
以下是jsfiddle的链接: http://jsfiddle.net/Qt972/
Here's a link to a jsfiddle: http://jsfiddle.net/Qt972/
当你运行小提琴时,你会看到一个名字和一个按钮,让人打个招呼。这样做很好,但是事件是未定义的。
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:
有谁知道如何解决这个问题问题?
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;
...
}
更新:自提交 657a2664 - 可在发布 0.9.6
我猜 - 只传递一个事件
参数,其视图和上下文作为属性。所以如果你想访问那些你必须做以下的事情:
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 action event.target未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!