2012-09-27 31 views
0

我有下表:轮换班,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-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> 

的问题是如何添加类的交替为TR的?像:class ='alt',class ='' - 请指教。

回答

1

您还可以在jQuery的放在一起工作示例:奇数或:即使选择。

$(".table tr:even").addClass('alt'); 

这不使用淘汰赛来解决答案,我知道,但有时候简单是好的。

+0

当使用KO构建表时,这将在第一次渲染表时生效。但是如果你做了任何导致表格被重新渲染(例如,改变任何值)的事情,你必须确保你再次调用它。 –

+0

photo_tom,是的,这也是如此。感谢您的支持。 –