我有这段代码(最新的ko版本):
<tbody>
<!-- ko foreach: searchResults-->
<tr>
<td><span class="capbType" data-bind="text: type"></span> (<span data-bind="text: data.length"></span>)</td>
<td class="capbEntities">
<!-- ko foreach: data -->
<p data-bind="text: name"></p>
//THIS IS NOT RENDERING
<!-- ko if: $index == 3 -->
<span class="capbShowMore capbIcon capbIconExpand" data-bind="visible: data.length > 3,click: $root.toggleShow"><span data-bind="text: data.length - 3"></span> More</span>
<!-- /ko -->
<!-- /ko -->
</td>
<td class="capbMoreInfo">
<!-- ko foreach: data -->
<p data-bind="text: strategyName"></p>
<!--/ko-->
</td>
</tr>
<!--/ko-->
</tbody>
我只是想capbShowMore
在 index 为时渲染元素一次,3
但由于某种原因,除了capbShowMore
元素之外的所有东西都被渲染了,所以我得到了这个:
<td class="capbEntities">
<!-- ko foreach: data -->
<p data-bind="text: name">FY13 SPM Strategy</p>
<!-- ko if:$index == 3 --><!-- /ko -->
<p data-bind="text: name">FY13 SPM Strategy</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name">FY11 Corporate Strategy</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Service & Portfolio Management</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Strategy1</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Strategy1</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Update Admin Users - default</p>
<!-- ko if: $data.$index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Update Admin Users - Duplicates</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<p data-bind="text: name" style="display: none;">Update Admin Users - Assignee is NULL</p>
<!-- ko if: $index == 3 --><!-- /ko -->
<!-- /ko -->
</td>
我究竟做错了什么?