vendredi 25 septembre 2015

Getting the value of element clicked on in Emberjs

I have a series of labels that I would like to retrieve the text from when the user clicks on them. I thought the jquery might be doable in Emberjs:

$(this).attr('text');

This however, doesn't work with Ember. My component view is this:

<ul class="list-inline">
  {{#each model as |model|}}
    <li {{action "sendToInput"}} class="label label-default">{{model.name}}</li>
  {{/each}}
</ul>

I would like to retrieve that model.name value via the action "sendToInput".

In my component js file I have tried:

actions: {
  sendToInput() {
    $(this.target).attr('text');
  }
}

I have also tried:

this.innerHTML;
$(this).text();
this.get('text');
$(this).val();

I have also opened up the console and dug through this and cannot seem to find where they store the element clicked on.

The documentation doesn't mention this and there's no issue I can find on the Github for ember-cli.

Thanks.




Aucun commentaire:

Enregistrer un commentaire