emberjs action event.target is undefined

蹲街弑〆低调 提交于 2019-12-20 04:13:38

问题


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:

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

Does anyone know how I can fix this issue?


回答1:


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: 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;
  ...
}


来源:https://stackoverflow.com/questions/9530912/emberjs-action-event-target-is-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!