【发布时间】:2015-10-27 11:43:33
【问题描述】:
我正在学习 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 > 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>
我的问题是,如果我的数组中有项目,我如何显示一个 HTML 块,如果数组没有任何项目,我如何显示另一个 HTML 块? h5 标记显示正确的项目数。因此,我知道我的绑定设置正确。但是,我不知道如何有条件地显示模板。
谢谢!
【问题讨论】:
标签: polymer