我正在制作一个小型活动日历,我想按开始时间对活动进行排序!
我在 grails 中使用 JodaTime 插件作为 startTime 属性。( http://www.grails.org/JodaTime+Plugin )
那么,我该如何使用这种数据类型进行排序呢?这不起作用:
def sortedEvents = events.asList().sort({ a, b -> a.startTime <=> b.startTime } as Comparator)
我希望你能帮帮我!
谢谢,whitenexx
/EDIT/ 这是我获取事件的代码:
def getEventsNext(Location location) {
def events = location.events.findAll { it.endTime >= new DateTime() }
def sortedEvents = events.sort{it.startTime}
System.out.println(sortedEvents); //test
return sortedEvents
}
在 /event/list 操作中,g:sortableColumn 一切正常(按 startTime 排序):