【问题标题】:Passing Event from Parent to Child Element (Polymer)将事件从父元素传递到子元素(聚合物)
【发布时间】:2016-07-19 03:23:20
【问题描述】:

我试图让一个父元素从它的子元素调用一个函数。在父母的剧本中,我有:

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

然后是它的孩子

listeners: {
    'send-update': '_update'
},

_update: function() {
    this.$$('#element').innerHTML = 0;
}

但孩子没有开火。

我已经使用设计模式成功地向上传递了一个函数。是否可以使用相同的模式向下传递?

【问题讨论】:

    标签: javascript polymer listener event-bubbling


    【解决方案1】:

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

    this.$.child._update();
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多