如何将数据从子自定义元素传递回 Polymer 2 中调用它的父元素

How to pass data from child custom element back to parent element from where it is called in Polymer 2

我在下面的聚合物中有这个自定义元素

 <parent-element> 
     <child-element myData="{{data}}"> </child-element>   <!--modifies the data-->
     <!-- Want to pass updated data to child-element-2-->

     <child-element-2> </child-element-2> 
 </parent-element>

告诉我如何将更新后的数据传递给第二个子元素

数据绑定是解决之道。
您应该在属性上使用破折号,而在属性中使用驼峰命名法。您可以在 Polymer 文档 Property name to attribute name mapping.

中阅读相关内容
<dom-module id="my-element">
  <template>
    <my-child-one data="{{data}}"></my-child-one>
    <my-child-two add-data="[[data]]"></my-child-two>
  </template>
  <script>
   Polymer({
     is: 'my-element',

       properties: {

         data: {
          type: String,
       },
   });
  </script>
</dom-module>

另外不要忘记在 my-child-one 元素内的 属性 上将 notify 设置为 true。