我有一个绑定到集合的ListView:
<ListView row="1" items="{{ measurements }}" id="measurement-list" loaded="" itemTap="">
<ListView.itemTemplate>
<GridLayout columns="5,*,10,*" rows="*, *" class="measurement-item">
<Label class="{{'severity-' + TrendArrow}}" col="0" rowSpan="2" text="" />
<Label class="measurement-value" col="1" text="{{ValueInMgPerDl}}" />
<Label class="measurement-uom" col="1" row="1" text="mg/dl"/>
<Label class="measurement-time" col="3" text="{{Timestamp}}"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
如果{{connections}}长度为0
,我想显示以下内容<Label col="1" text="No Measuremenets Available" textWrap="false" />
其他明智的我想要显示item.Template上面。我怎样才能做到这一点?到目前为止,我所尝试的一切都失败了。视图模型有一个布尔hasMeasurement
属性,但是当我尝试在XML中执行以下操作时失败,任何指导? UI最终只在每个表项中显示[对象对象]。
<ListView row="1" items="{{ measurements }}" id="measurement-list">
<ListView.itemTemplate>
<GridLayout columns="5,*,10,*" rows="*, *" class="measurement-item" visibility="{{ hasMeasurement ? 'visible' : 'collapsed' }}">
<Label class="{{'severity-' + TrendArrow}}" col="0" rowSpan="2" text="" />
<Label class="measurement-value" col="1" text="{{ValueInMgPerDl}}" />
<Label class="measurement-uom" col="1" row="1" text="mg/dl"/>
<Label class="measurement-time" col="3" text="{{Timestamp}}"/>
</GridLayout>
<GridLayout rows="" columns="" visibility="{{ hasMeasurement ? 'visible' : 'collapsed' }}" >
<Label text="No Measurements Available" textWrap="false" />
</GridLayout>
</ListView.itemTemplate>
</ListView>
答案 0 :(得分:3)
您可以尝试这个,具体取决于主容器的内容,在本例中为GridLayout:
<Label row="1" text="No Measuremenets Available" textWrap="false" visibility="{{ measurements.length, measurements.length === 0 ? 'visible' : 'collapsed' }}" />
<ListView row="1" items="{{ measurements }}" id="measurement-list" loaded="" itemTap="" visibility="{{ measurements.length, measurements.length === 0 ? 'collapsed' : 'visible' }}" >
<ListView.itemTemplate>
<GridLayout columns="5,*,10,*" rows="*, *" class="measurement-item">
<Label class="{{'severity-' + TrendArrow}}" col="0" rowSpan="2" text="" />
<Label class="measurement-value" col="1" text="{{ValueInMgPerDl}}" />
<Label class="measurement-uom" col="1" row="1" text="mg/dl"/>
<Label class="measurement-time" col="3" text="{{Timestamp}}"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
请注意标签和列表视图中的以下行以及它们如何“反转”:
visibility="{{ measurements.length, measurements.length === 0 ? 'visible' : 'collapsed' }}"