Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data binding for dynamically generated HTML in Polymer?

Tags:

polymer

When I write the following inside my <template>-tag, everything works fine:

<ul id="breadcrumbList" class="breadcrumb">
    <li><a on-click="{{breadcrumbClick}}">{{overviewName}}</a></li>
</ul>

I dynamically generated a new <li>-element of the same structure, like this:

crumb = document.createElement("li");
crumb.innerHTML = '<a on-click="{{breadcrumbClick}}">'+category+'</a>';

But when I click this element, the event-handler isn't called.

The event-handler looks like this:

breadcrumbClick: function(event, detail, sender) {
     /*reaction*/
}

I did not find any documentation about whether it's possible or impossible to use data binding for dynamically generated content.

like image 931
Arne N Avatar asked Sep 12 '26 04:09

Arne N


1 Answers

This is possible with injectBoundHTML(). We haven't documented it yet, but you can see the method signature and demo here: https://github.com/Polymer/docs/issues/607

Example:

<li id="myli></li>

this.injectBoundHTML('<a on-click="{{breadcrumbClick}}">...</a>', this.$.myli);
like image 123
ebidel Avatar answered Sep 19 '26 07:09

ebidel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!