我正在使用Full Calendar插件。我希望事件排序是根据开始日期/时间升序。如下所示event # 2
,event # 3
& event # 4
的顺序正确,但event # 1
的顺序不正确。它应该是最后一个。
错误的订单:
[
{"id":"1","title":"AAA","start":"2013-04-01 00:00:00","end":"2013-04-01 23:59:59", "allDay":false},
{"id":"2","title":"BBB","start":"2013-04-01 07:30:00","end":"2013-04-01 09:30:00", "allDay":false},
{"id":"3","title":"CCC","start":"2013-04-01 08:00:00","end":"2013-04-01 10:30:00", "allDay":false},
{"id":"4","title":"DDD","start":"2013-04-01 13:00:00","end":"2013-04-01 10:30:00", "allDay":false},
]
我希望它如何(按时间顺序ASC):
[
{"id":"2","title":"BBB","start":"2013-04-01 07:30:00","end":"2013-04-01 09:30:00", "allDay":false},
{"id":"3","title":"CCC","start":"2013-04-01 08:00:00","end":"2013-04-01 10:30:00", "allDay":false},
{"id":"4","title":"DDD","start":"2013-04-01 13:00:00","end":"2013-04-01 10:30:00", "allDay":false},
{"id":"1","title":"AAA","start":"2013-04-01 23:00:00","end":"2013-04-01 23:59:59", "allDay":false}
]
Week View
& Day View
,但未在Month View
完美排序。所有事件都来自数据库,我将JSON提要传递给fullcalendar
以呈现事件。在这方面的任何帮助将受到高度赞赏。
答案 0 :(得分:0)
您可以使用underscore.js对对象数组进行排序。
var events = [
{"id":"1","title":"AAA","start":"2013-04-01 23:00:00","end":"2013-04-01 23:59:59", "allDay":false},
{"id":"2","title":"BBB","start":"2013-04-01 07:30:00","end":"2013-04-01 09:30:00", "allDay":false},
{"id":"3","title":"CCC","start":"2013-04-01 08:00:00","end":"2013-04-01 10:30:00", "allDay":false},
{"id":"4","title":"DDD","start":"2013-04-01 13:00:00","end":"2013-04-01 10:30:00", "allDay":false}
];
var sortedEvents = _.sortBy(events, function(data){ return data.start; });
<强> DEMO 强>