我有一個聚合物元素是這樣的:如何創建動態聚合物元件簡單的標籤
<polymer-element name="x-block" attributes="data">
<template>
<div class="block-wrapper">
<div class="plus-button"on-click="{{showMdl}}">+</div>
<div hidden?="{{!showModal}}" id="modal">
Modal
</div>
<content select="header"></content>
</div>
</template>
/*Polymer */
<script>
Polymer({
ready: function(){
this.showModal = false;
},
showMdl: function(e,detail,sender){
this.showModal = true;
this.$.modal.style.top = e.layerY+'px';
this.$.modal.style.left = e.layerX+'px';
var newElement = document.createElement('div')
newElement.innerHTML = 'dynamicllyElement';
newElement.setAttribute('on-click','{{clickOnDynamicllyElement}}');
this.$.modal.appendChild(newElement);
},
clickOnDynamicllyElement:function(){
console.log('1111')
}
});
</script>
</polymer-element>
clickOnDynamicllyElement
不起作用。
注意:我的答案可能是矯枉過正。最好只使用 'newElement.addEventListener('click',this.clickOnDynamicllyElement.bind(this));' Scott聚合物小組解釋了這裏(https://groups.google.com/forum) /#!msg/polymer-dev/I5t73SGLLNc/UlYvEa508pkJ)只有當您確實需要綁定動態HTML數據時,纔會使用injectBoundHTML,而不是僅僅監聽事件。 – sfeast 2014-10-29 20:30:47