2016-08-23 54 views
0

我已经包含另一聚合物组分内像这样的聚合物组分添加聚合物组件属性动态

<dom-module id="custom-component2"> 
    <template> 
     <custom-component1 id="component1" type="abc" config="xyz"></custom-component1> 
    </template> 
</dom-module> 
<script> 
Polymer({ 
    is: 'custom-component2', 
    properties: { 

    }, 
    ready: function() { 

    }, 
    init: function() { 

    } 
}); 
</script> 

反正我有可以添加的属性,如类型,配置为我的“定制COMPONENT1”动态喜欢 -

<dom-module id="custom-component2"> 
    <template> 
     <custom-component1 id="component1"></custom-component1> 
    </template> 
</dom-module> 
<script> 
Polymer({ 
    is: 'custom-component2', 
    properties: { 

    }, 
    ready: function() { 
     self.$.component1.type = "abc"; 
     self.$.component1.config = "xyz"; 
    } 
}); 
</script> 

或者我可以将这些选项作为一个整体作为对象传递吗?

请问有人可以帮我吗?

回答

0

这应该工作:

<dom-module id="custom-component2"> 
    <template> 
     <custom-component1 id="component1"></custom-component1> 
    </template> 
</dom-module> 
<script> 
Polymer({ 
    is: 'custom-component2', 
    properties: { 

    }, 
    attached: function() { 
     this.$.component1.type = "abc"; 
     this.$.component1.config = "xyz"; 
    } 
}); 
</script> 

使用数据绑定与对象:

<dom-module id="custom-component2"> 
    <template> 
     <custom-component1 id="component1" data={{_data}}></custom-component1> 
    </template> 
</dom-module> 
<script> 
Polymer({ 
    is: 'custom-component2', 
    properties: { 
     _data:{ 
      type: Object, 
      value: function(){ 
        return {type:"abc", config:"xyz"}; 
      } 
     }, 
    }, 
}); 
</script>