我有一种聚合物成分包含在另一种聚合物成分中,如此
<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>
无论如何,我可以为我的&#34; custom-component1&#34;添加类型,配置等属性。动态地像 -
<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 :(得分: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>