I'm trying to send object as params of on-click functions, I already saw some posts using data-xxx to send values and retrieving them with the target.attributes field but that works only for strings and not objects.
Here is a jsbin showing the problem: http://jsbin.com/tujekilafowa/1/edit?html,console,output
There is a solution, even though its terrible, by using JSON.stringify to send the data and retrieving them with JSON.parse: http://jsbin.com/lavocacadoti/1/edit?html,console,output
Is there a better way?
In a perfect world, I would like it to work as Angular by passing parameters to a function directly inside the HTML call...
EDIT
I opened an issue on polymer project about this problem.
Taking Peters answer above, this works for me (if it is enough to access the model)...
Polymer Element Template:
<template>
<template repeat="{{ address in addresses }}">
<paper-button label="-" on-click="{{ callback }}">less</paper-button>
</template>
</template>
The Polymer Callback looks like this:
Polymer({
callback: function (event, detail, sender) {
console.log(sender.templateInstance.model.address);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With