显示模板中的两个值之一
Show one of the two values in the template
我有一个简单的元素:
<dom-module id="example-element">
<template>
<span>{{showAorB??}}</span>
</template>
<script>
Polyemer({
is: 'example-element',
parameters: {
a: String,
b: String
}
});
</script>
</dom-module>
我是这样使用的:
<example-element a="{{a}}" b="{{b}}">
在我的场景中,a
或 b
之一始终是 undefined
。
我感到困惑的是如何实现{{showAorB}}
部分。基本上我想要的是 a || b
.
我尝试过的:
- computed 属性 / function (
{{showAorB(a,b)}}
) - 不起作用,因为它等待 a
和 b
成为 !== undefined
,在我的例子中,意味着它永远等待
<span hidden$='{{!a}}'>{{a}}</span><span hidden$='{{!b}}'>{{b}}</span>
- 太尴尬了
实现这个的正确方法是什么?
使用函数语法 ({{showAorB(a,b)}}
) 但在你的 properties
声明中(你显示 parameters
但它应该是 properties
)给出 a
和b
虚假(但不是 undefined
)值。像这样:
properties: {
a: {
value: ''
},
b: {
value: ''
}
},
我有一个简单的元素:
<dom-module id="example-element">
<template>
<span>{{showAorB??}}</span>
</template>
<script>
Polyemer({
is: 'example-element',
parameters: {
a: String,
b: String
}
});
</script>
</dom-module>
我是这样使用的:
<example-element a="{{a}}" b="{{b}}">
在我的场景中,a
或 b
之一始终是 undefined
。
我感到困惑的是如何实现{{showAorB}}
部分。基本上我想要的是 a || b
.
我尝试过的:
- computed 属性 / function (
{{showAorB(a,b)}}
) - 不起作用,因为它等待a
和b
成为!== undefined
,在我的例子中,意味着它永远等待 <span hidden$='{{!a}}'>{{a}}</span><span hidden$='{{!b}}'>{{b}}</span>
- 太尴尬了
实现这个的正确方法是什么?
使用函数语法 ({{showAorB(a,b)}}
) 但在你的 properties
声明中(你显示 parameters
但它应该是 properties
)给出 a
和b
虚假(但不是 undefined
)值。像这样:
properties: {
a: {
value: ''
},
b: {
value: ''
}
},