使用Knockout.JS替换类
我有下一张桌子:使用Knockout.JS替换类,knockout.js,Knockout.js,我有下一张桌子: <table class="table" id="calls_table"> <thead> <tr> <th class="round-bg header">Val1</th> <th class="rep-bg header">Val2</th> <th class="rep-b
<table class="table" id="calls_table">
<thead>
<tr>
<th class="round-bg header">Val1</th>
<th class="rep-bg header">Val2</th>
<th class="rep-bg header">Val3</th>
</tr>
</thead>
<tbody data-bind="template: {name: 'call-template', foreach: calls}">
</tbody>
</table>
<script type="text/html" id="call-template">
<tr class="alt">
<td><a data-bind="attr: {href: url}, text: v1" class="simp" href=""></a></td>
<td><a data-bind="attr: {href: url}, text: v2" class="simp" href=""></a></td>
<td data-bind="text: v3"></td>
</tr>
</script>
瓦尔1
瓦尔2
Val3
问题是如何为TR添加类替换?比如:class='alt',class='''--请告知 这个问题在这里得到了回答
我在上整理了一个工作示例,您也可以使用jQuery:odd或:偶数选择器
$(".table tr:even").addClass('alt');
我知道,这不会使用敲除来解决问题,但有时简单是好的。使用KO构建表时,这在第一次呈现表时起作用。但是,如果您做了任何导致表被重新呈现的事情(例如,更改任何值),您必须确保再次调用它。谢谢你接电话。