我想访问 ember 操作中的事件对象以检查目标元素。这适用于 Chrome 和 Safari,但不适用于 Firefox 25.0。
我什至没有收到错误消息。如何访问 ember 操作中的事件对象,或者有没有 ember 方法可以做到这一点?
如何重现:
- 打开我的小提琴
- 单击应该打开警报框的 div 或“单击我”链接
- 在 chrome 和 firefox 中测试这些
HTML
<script type="text/x-handlebars" data-template-name="application">
<h1>Click the link in the following div</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
{{test-a}}
</script>
<script type="text/x-handlebars" data-template-name="components/test-a">
<div class="index" {{action 'edit' on="click"}}>
<a href="http://www.example.com" target="_blank">Click me</a>
</div>
</script>
咖啡
App = Ember.Application.create({});
App.TestAComponent = Ember.Component.extend
actions:
edit: ->
if event.toElement.nodeName.toUpperCase() == 'A'
return true # should bubble to the window but is a component
# do something for editing here
alert('div clicked')
false
CSS
h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
ul { padding: 15px; font-size: 1.4em; color: green; }
.index { background-color: #666; padding: 20px; }