向使用Jquery TableSorter排序的knockout observable数组添加新行会将行添加两次,这会导致已存在的行重复.PFB my code:
<tbody data-bind="foreach: jarFiles"> //jarFiles:KnockoutArray
<td><span data-bind="text: fileName"></span></td>
<td><span data-bind="text: name"></span></td>
<td>...</tbody>
点击前两行应用排序:
$( "#fileName" ).click(function() {
$("#display").tablesorter();
}//Invokes tablesorter on click function for fileName column
排序后我尝试更新表格格式的数组,它返回重复项:
that._replace = function(newList) {//newList=oldList+newelement
that.jarFiles.removeAll()
var i=newList.length;
_.each(newList, function(jar){
that.jarFiles.push(jar);
});
使用ajax加载页面。
答案 0 :(得分:0)
that._replace = function(newList) {
that.jarFiles.removeAll();
$(".display").find('tbody').empty(); // To clear table body
_.each(newList, function(jar){
that.jarFiles.push(jar);
});
$(".display").trigger("update"); // To update the tablesorter
};