JQuery比较表数据

时间:2012-06-27 13:40:42

标签: jquery comparison

我有一个由日期分隔的大型数据表(显示测试数据)。我使用JQuery对这个数据进行POST处理(该表是用Perl构建的,并且排序实际上不能在那里完成)。在按日期对数据进行排序之后,我想在每天之间添加一条分隔线。

例如,我想从6月5日开始进行五次测试,然后是一个空白行(一个空白的“tr”,稍后会添加数据,但这里不重要),然后是6月4日然后是空白行,然后是6月3日运行等等。

以下是我的表格示例:http://jsfiddle.net/pyUz8/1/

这是我的伪代码,只是不确定如何在JQuery中执行此操作:

  

now = thisDate.substring(0,10)//只查看日期和时间   无关紧要= previousDate.substring(0,10)

     

if(then!= now)insert("<tr></tr>"); //介于当时和现在

如何在JQuery中完成?

1 个答案:

答案 0 :(得分:1)

遍历每一行,将当前日期与下一个日期进行比较,如果日期不同,则在当前行之后插入tr。像这样:

$('tr').each(function(){
  var current_date = $(this).children('.date_cell').val() // or whatever you call your date cell
  var next_date = $(this).next().children('.date_cell').val() // also strip these evaluations from the time as you described...
  if (current_date != next_date){
    $(this).after('<tr class="blank_row"></tr>)
  }
})