문제

Question: Upon click, I see that evt.target.attributes stores all of the attributes in an array. Is there an easier way without having to iterate all of the attributes to get a certain attributes value? In this example I need the value of the 'note' attribute for the element clicked.

Template:

<a note="C" {{action "play" on="click"}}>></a>

Click handler(play):

var keys = Ember.View.create({
    templateName: 'keys',
    notes: this.get('allKeys'),
    play:function(evt){
        var attributes= evt.target.attributes;
        console.log(attributes);
    }
도움이 되었습니까?

해결책

If a controller isn't backing the view, one solution is to turn the event target into a jQuery object

play : function(event) {
    var note = $(event.target).attr("note");
    // More code here
}

다른 팁

Another way is to pass the attribute value as parameter to the action.

<a note="C" onClick={{action "play" value="target.note"}}></a>

And you can access it like this:

...
actions: {
    play(note) {
        console.log(note);
    },
},
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top