Javascript 将事件从父元素传递到子元素(聚合物)
我试图让父元素从它的子元素调用函数。在家长的脚本中,我有:Javascript 将事件从父元素传递到子元素(聚合物),javascript,polymer,listener,event-bubbling,Javascript,Polymer,Listener,Event Bubbling,我试图让父元素从它的子元素调用函数。在家长的脚本中,我有: _handleFunction: function() { console.log("Button Pressed!"); this.fire('send-update'); } 然后在它的孩子 listeners: { 'send-update': '_update' }, _update: function() { this.$$('#element').innerHTML = 0; } 但孩子
_handleFunction: function() {
console.log("Button Pressed!");
this.fire('send-update');
}
然后在它的孩子
listeners: {
'send-update': '_update'
},
_update: function() {
this.$$('#element').innerHTML = 0;
}
但孩子没有开枪
我已经使用设计模式成功地向上传递了一个函数。是否可以使用相同的模式向下传递?调用子元素的_update()函数的最简单方法是直接从父元素_handleFunction()调用它: 其中子元素的HTML id必须为“child”
this.$.child._update();