问题:单击后,我看到 evt.target.attributes 将所有属性存储在一个数组中。有没有一种更简单的方法,而不必迭代所有属性来获取某个属性值?在此示例中,我需要单击的元素的“note”属性值。
模板:
<a note="C" {{action "play" on="click"}}>></a>
点击处理程序(播放):
var keys = Ember.View.create({
templateName: 'keys',
notes: this.get('allKeys'),
play:function(evt){
var attributes= evt.target.attributes;
console.log(attributes);
}
最佳答案
如果 Controller 不支持 View ,一种解决方案是将事件目标转换为 jQuery 对象
play : function(event) {
var note = $(event.target).attr("note");
// More code here
}
关于ember.js - Emberjs - 获取单击的元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9370078/