2014-11-06 69 views
0

從這裏https://www.polymer-project.org/articles/communication.html#events谷歌聚合物監聽火災事件從未發生過

把沒有完全工作實施起來,我想獲得的addEventListener對不同的組件或DOM元素工作。 如果我把偵聽器放在提交組件上,它會起作用,但是如果我把它放在dom元素上沒有任何反應的話,那麼這個示例就會起作用。 使發送元素上的偵聽器看起來多餘。

我看着數據綁定,但我想傳遞更多的數據,真的只是想建立一個工作小型演示庫的庫,我可以參考當我需要不同的方法。

謝謝。

<body unresolved id="body"> 

<polymer-element name="say-hello" attributes="name" on-click="{{sayHi}}"> 
    <template>Hello {{name}}!</template> 

    <script> 
    Polymer('say-hello', { 
     sayHi: function() { 
     console.log("sklngh"); 
     this.fire('said-hello', {name: this.name}); 
     } 
    }); 
    </script> 

</polymer-element> 


<say-hello></say-hello> 

<div id="container">zzz</div> 

<script> 
    var container = document.querySelector('#container'); 
    // var container = document.querySelector('say-hello'); 
    container.addEventListener('said-hello', function(e) { 
     alert('outside: Said hi to ' + e.detail.name + ' from ' + e.target.localName); 
    }); 
</script> 

</body> 

編輯

啊它泡!需要包裝組件。

<div id="container"> 
    <say-hello></say-hello> 
</div> 

回答

0

請參閱上面的修改。這似乎是答案。咔嚓。