KnockoutJs与Jquery.tablesorter - 导致重复行

naw*_*rgs 5 jquery tablesorter knockout.js

http://jsfiddle.net/nalberg/E3nBu/4/

对此有何帮助?我在使用时获取重复行:KnockoutJs:http://knockoutjs.com/和jquery.tablesorter插件:(http://tablesorter.com/docs/).

基本上,第一次加载......它的效果很好.但是如果我在排序表之后替换或更改绑定到挖空数据的数据......我开始获得重复的行.每个似乎都在创建和维护自己的行集.

小智 0

我有一个解决方案给你。尽管它可能会很慢,但它确实有效。解决方案是使用模板并使用jquery。each代替foreach。这是html中的代码:

 // replace this div with the table
 <div id="peopleTemplateContainer"  data-bind="{template: 'peopleTemplate' }">

     <script id="peopleTemplate" type="text/html">
     <table id="dataGrid" border="1">
       <thead>
        <tr>
        <th><b>Sortable Header (sort click me)</b></th>
        </tr>
       </thead>
       <tbody >
          {{each(index,compliance) people()}}
        <tr >
            <td >${data}</td>
        </tr>
       {{/each}}
       </tbody>
     </table>
     </script>
Run Code Online (Sandbox Code Playgroud)