0

我正在使用完整日历插件。我希望事件的顺序是根据开始日期/时间升序排列的。正如您在下面看到的event # 2event # 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呈现事件。在这方面的任何帮助将不胜感激。

4

1 回答 1

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; });

演示

于 2013-04-05T02:45:08.237 回答