目前,我正在尝试使用jQuery表分类器插件对我的表行进行排序。目前,我的表数据将每60秒更新一次,所以如果我在60秒之前开始排序,它会正常工作,但在60秒之后,如果我试图排序我的表行,它会重复。我能知道原因是什么以及如何解决这个问题吗。提前谢谢。
这是我的jquery代码:
$(document).ready(function(){
setTimeout(function(){
if($(".tablesorter").find('tbody:first tr').length > 0){
$(".tablesorter").tablesorter();
$(".tablesorter").trigger('update');
alert("success");
}
}, 5000);
});
不使用setTimeout
来更新表分类器,而是在之后更新表分类器,无论ajax函数从表中添加或删除内容。类似这样的东西:
// tablesorter initialized outside of the ajax process
$("table").tablesorter();
$.ajax("load-new-stuff.php")
.done(function(data) {
// process the data and add it to the table
addData(data);
})
.fail(function() {
$("table tbody").html("<tr><td colspan='5'>Error</td></tr>");
})
.always(function() {
$("table").trigger("update");
});