将事件从父元素传递到子元素(聚合物)

Passing Event from Parent to Child Element (Polymer)

本文关键字:元素 聚合物 事件      更新时间:2023-09-26

我正试图让父元素从其子元素调用函数。在家长的脚本中,我有:

_handleFunction: function() {
    console.log("Button Pressed!");
    this.fire('send-update');
}

然后在它的子

listeners: {
    'send-update': '_update'
},
_update: function() {
    this.$$('#element').innerHTML = 0;
}

但孩子没有开枪。

我已经使用设计模式成功地向上传递了一个函数。有可能用同样的模式传下去吗?

调用子元素的_update()函数的最简单方法是直接从parent_handleFunction()调用它:

this.$.child._update();

其中子元素的HTML id必须为"child"。