我有许多事件是全天的事件,并且都是在同一时间开始的。我按照希望它们在完整日历视图上显示的顺序创建事件,但它们似乎总是以其他方式排序。
如何按字母顺序或按id对事件进行排序?
编辑:添加数据的示例数组。在日历中,我预计Supervisor事件每天都会出现在第一位,按字母顺序排在Tech1和Tech2之前,它的id也是以下事件的出租编号。相反,我每天都会得到一个随机的订单。
例如:
day of 2011-11-05订单显示为Tech2、Tech1、Tech2、Supervisor。
day of 2011-11-06订单显示为Supervisor、Tech1、Tech2、Tech2。
我要求排序至少每天保持一致,理想情况下是按照标题的字母顺序或id的顺序排序。
var events=[
{id:1, title:'Supervisor',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:2, title:'Tech2',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:3, title:'Tech2',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:4, title:'Tech1',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:5, title:'Tech1',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:6, title:'Tech1',start:'2011-11-05T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:7, title:'Supervisor',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:8, title:'Tech2',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:9, title:'Tech2',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:10, title:'Tech1',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:11, title:'Tech1',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true},
{id:12, title:'Tech1',start:'2011-11-06T00:00:00-05:00',st_hours:10,ot_hours:0,allDay:true}
];
EDIT2:这个问题似乎只存在于Google Chrome中。事件按照我期望的顺序呈现在IE9和FF8中。我用来开发的Chrome15似乎是唯一受影响的浏览器。
铬
FireFox
发布于 2015-12-06 05:08:30
按颜色排序的缩小版本。
compareSegs:function(a,b){if(this.view.name=="basicWeek"){return b.event.allDay-a.event.allDay||B(a.event,b.event,this.view.eventOrderSpecs)}else{return a.eventStartMS-b.eventStartMS||b.eventDurationMS-a.eventDurationMS||b.event.allDay-a.event.allDay||B(a.event,b.event,this.view.eventOrderSpecs)}
https://stackoverflow.com/questions/8231902
复制相似问题