如果数组为空,我需要显示一条消息,否则我需要表中显示的数据。
到目前为止,这是我所拥有的(并且不起作用):
<div data-bind="if: interruptions().length == 0">No service interruption has been scheduled</div>
<table id="newsTbl" class="display compact table-bordered table-striped table-condensed table-hover" style="width: 100%">
<thead>
<tr>
<th>Title</th>
<th>Body</th>
<th>Extra</th>
<th>Start Date</th>
</tr>
</thead>
<tbody data-bind="foreach: interruptions">
<tr>
<td data-bind="text: title"></td>
<td data-bind="text: body"></td>
<td data-bind="text: extra"></td>
<td data-bind="text: startDate"></td>
</tr>
</tbody>
</table>
如何在此处添加其他内容?
答案 0 :(得分:0)
Knockout中没有内置else
。您需要使用另一个if
,这是对第一个if
的否定。
<div data-bind="if: interruptions().length == 0">No service interruption has been scheduled</div>
<!-- ko if: interruptions().length > 0 -->
<table id="newsTbl" class="display compact table-bordered table-striped table-condensed table-hover" style="width: 100%">
<!-- /ko -->
从Knockout 3.3开始,你唯一的另一个选择就是knockout-switch-case,它为Knockout增加了else
个功能。