Polymer 聚合物条件模板
我正在学习聚合物。现在,我正在尝试有条件地显示一个模板 my component.htmlPolymer 聚合物条件模板,polymer,Polymer,我正在学习聚合物。现在,我正在尝试有条件地显示一个模板 my component.html <dom-module id="my-component"> <template> <h5>There are <span>[[ orders.length ]]</span> orders.</h5> <template is="dom-if" if="[[ orders.length >
<dom-module id="my-component">
<template>
<h5>There are <span>[[ orders.length ]]</span> orders.</h5>
<template is="dom-if" if="[[ orders.length > 0]]">
<template is="dom-repeat" items="{{ orders }}" as="order">
<div class="order-item">
<span>[[ order.description ]]</span>
</span>
</template>
</template>
<template is="dom-if" if="[[ orders.length == 0]]">
No orders have been placed
</template>
</template>
<script>
Polymer({
is: "my-component",
properties: {
orders: Array
}
});
</script>
</dom-module>
有[[orders.length]]个订单。
[[order.description]]
尚未下订单
聚合物({
是:“我的组件”,
特性:{
订单:数组
}
});
我的问题是,如果我的数组中有项目,如何显示一个HTML块,如果数组中没有任何项目,如何显示另一个HTML块?h5
标签显示了正确的项数。因此,我知道我的绑定设置正确。但是,我不知道如何有条件地显示模板
谢谢大家! 聚合物不支持这种功能。通常,如果需要表达式,则需要使用。在这种特定情况下,因为0的计算结果为
false
,其他值的计算结果为true
,您可以这样做:
<template is="dom-if" if="[[ orders.length ]]">
<template is="dom-repeat" items="{{ orders }}" as="order">
<div class="order-item">
<span>[[ order.description ]]</span>
</div>
</template>
</template>
<template is="dom-if" if="[[ !orders.length ]]">
No orders have been placed
</template>
[[order.description]]
尚未下订单