我希望函数的Polymer
对象设置属性值,如果未设置默认值,则取决于其他属性
Polymer({
is: "my-element",
properties : {
a: String,
b: String,
c: {
type: String,
value: function() {return " " + this.a + " " + this.b}
}
},
calcC: function() {return " " + this.a + " " + this.b}
});
我怎么能意识到它?
<dom-module id="my-element">
<template>
<p>a: {{a}}</p>
<p>b: {{b}}</p>
<p>c: {{c}}</p>
<p>calc c: {{calcC()}}</p>
</template>
</dom-module>
<my-element a="a" b="b"></my-element>
渲染
a: a
b: b
c: undefined undefined
calc c: undefined undefined
答案 0 :(得分:0)
怎么样
<dom-module id="my-element">
<template>
<p>a: {{a}}</p>
<p>b: {{b}}</p>
<p>c: {{c}}</p>
</template>
</dom-module>
<my-element a="a" b="b"></my-element>
<my-element a="a" b="b" c="c"></my-element>
Polymer({
is: "my-element",
properties: {
a: String,
b: String,
c: String
},
ready: function () {
if (this.c == undefined) {
this.c = " " + this.a + " " + this.b;
}
}
});
a:a
b:b
c:a b
a:a
b:b
c:c