从这里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>