How do I pass a dom-repeated item inside a function in on-click? My code doesn't work:
<dom-module id="my-element">
<template>
<template is="dom-repeat" items="{{stuff}}>
<paper-button on-click="_myFunction(item.name)">{{item.name}}</paper-button>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element',
ready: function() {
this.stuff = [
{ id: 0, name: 'Red' },
{ id: 1, name: 'Blue' },
{ id: 2, name: 'Yellow' },
];
},
_myFunction: function(color) {
console.log('You pressed button ' + color);
},
})
</script>
Or is there a better approach in achieving something like this? Thanks!