检查时间重叠

你好
我已经通过将值放入数组并对它们进行排序来检查时间的重叠.
在这里,当单元格为空时,我无法将数据插入单元格!
我的代码是:

选择 | 换行 | 行号
  1. <script>
  2. function compare_row_time()
  3. {
  4.   var all_times= new Array();
  5.   var flag_check=false;
  6.   var count_times=0;
  7.   for(var i=0;i<mygrid.getRowsNum();i++)
  8.   {
  9.     var time_1=mygrid.cells2(i,1).getValue();//starttime value of i
  10.     var time_2=mygrid.cells2(i,2).getValue();//endtime value of i
  11.     all_times[count_times]=time_1;
  12.     count_times++;
  13.     all_times[count_times]=time_2;
  14.     count_times++;
  15.   }
  16.   var sort_times= new Array();
  17.   sort_times=all_times.sort();
  18.   for(var j=0; j<sort_times.length;j++)
  19.   {
  20.     if(sort_times[j]==sort_times[j+1])
  21.      {
  22.        flag_check=true;//if false data is inserted even it is wrong.
  23.      }
  24.   }
  25.    return flag_check;
  26. }   
  27.  
  28. function save()
  29. {
  30.   if(!compare_row_time())
  31.    {
  32.     myDataProcessor.sendData();//sending data to server
  33.    }
  34.   if(err_str!="")//error_msg
  35.   alert(err_str);
  36.    err_str="";
  37. }
  38. </script>
  39.  

1.在排序时间数组中,如果存在任何重复值,它将显示错误(这仅在IM检查网格中的现有数据时有效)
2.如果im在空行中插入新值,im将无法发送数据(如果我在[排序时间数组]中将FLAG_CHECK更改为FALSE,则无法插入值,但如果我提供重复的值,数据也将被插入.此条件为FALSE)
3.我的时间模式是用户可以输入05:00或5:00的时间(如果一行的时间为5:00,而另一行的时间为05:00,则不进行比较;如果模式的类型相同,则会检查是否存在重复项)
4.如何突出显示重复的单元格并为其提供消息.
有人能在没有这些错误的情况下重建上面的代码吗?
谢谢.
问候
纳里娜

# 回答1


我已经用计数器检查了循环,并向Time_1和Time_2值发出警报
我得到的输出和
对于循环j:
从0到7的计数器
Time_1 Time_2
6:00未定义
16:02 7:00
8:00 16:30
17:00 09:00
18:02
但实际数据是
Time_1 Time_2
6:00 7:00
16:02 16:30
8:00 9:00
17:00 18:02
当IM提示重叠单元格的消息时,每次都显示最后一行的警告,
问题在于设置FLAG_STATUS=TRUE;

标签: Javascript

添加新评论