2016-08-23 91 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>