Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Event handling #19

Closed
shawnbot opened this issue May 28, 2016 · 1 comment
Closed

Event handling #19

shawnbot opened this issue May 28, 2016 · 1 comment

Comments

@shawnbot
Copy link
Owner

This is in the works in #18, but I wanted to have an issue to track it just in case it doesn't make the next release. Here's how it should work:

<div id="template">
  <button t-each="buttons" t-onclick="(d, e) => click(d)">{{ . }}</button>
</div>
<script>
tagalong.render('#template', ['a', 'b', 'c'], {
  click: function(data, event) {
    alert('clicked: ' + data);
  }
});
</script>

You have to use the fat arrow syntax to get access to the event object, which is passed as the second argument. (We could do things like D3 and just stash the event in tagalong.event, too.) If you don't need access to the event and only need access to properties of the data and/or context, you can write a handler like:

<button t-onclick="click(foo)">{{ foo }}</button>

...which assumes that the data being rendered in that node is an object with a foo property, and the click property is a function of either the data or the rendering context.

@shawnbot
Copy link
Owner Author

shawnbot commented Jun 1, 2016

Fixed in #18! You must use a function (or fat arrow) expression to gain access to the event object, though.

@shawnbot shawnbot closed this as completed Jun 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant