i have series of labels retrieve text when user clicks on them. thought jquery might doable in emberjs:
$(this).attr('text');
this however, doesn't work ember. component view this:
<ul class="list-inline"> {{#each model |model|}} <li {{action "sendtoinput"}} class="label label-default">{{model.name}}</li> {{/each}} </ul>
i retrieve model.name value via action "sendtoinput".
in component js file have tried:
actions: { sendtoinput() { $(this.target).attr('text'); } }
i have tried:
this.innerhtml; $(this).text(); this.get('text'); $(this).val();
i have opened console , dug through , cannot seem find store element clicked on.
the documentation doesn't mention , there's no issue can find on github ember-cli.
thanks.
the common way pass model name action parameter this:
<ul class="list-inline"> {{#each model |model|}} <li {{action "sendtoinput" model.name}} class="label label-default">{{model.name}}</li> {{/each}} </ul>
and handle in action:
actions: { sendtoinput(name) { // name } }
but if still need access exact element's html, there workaround:
export default ember.component.extend({ didinsertelement () { this.$().on('click', '.label', function (event) { $(this).text(); }) } });
Comments
Post a Comment