【发布时间】:2015-08-19 10:22:01
【问题描述】:
我正在使用 FullCalendar 将日历添加到我的 Play java 应用程序中,我只需要在日历中显示我的事件。为此,我有一个 JavaScript 路由器,这是我的控制器:
public class Utilities extends Controller {
public static Result javascriptRoutes() {
response().setContentType("text/javascript");
return ok(
Routes.javascriptRouter("myJsRoutes",
routes.javascript.Utilities.json()
)
);
}
public static Result json(Long start, Long end) throws ParseException {
ArrayList<Map<Object, Serializable>> allEvents = new ArrayList<Map<Object, Serializable>>();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date startDate = df.parse("2015-08-14 00:00");
Date endDate = df.parse("2015-08-19 00:00");
Map<Object, Serializable> eventRemapped = new HashMap<Object, Serializable>();
eventRemapped.put("id", 1l);
eventRemapped.put("title", "test title");
eventRemapped.put("start", df.format(startDate));
eventRemapped.put("end", df.format(endDate));
eventRemapped.put("allDay", true);
allEvents.add(eventRemapped);
return ok(play.libs.Json.toJson(allEvents));
}
}
我的页面标题中有这一行:
<script type="text/javascript" src='@routes.Utilities.javascriptRoutes()'></script>
我的路线中有这两条线
GET /javascriptRoutes controllers.Utilities.javascriptRoutes
GET /events.json controllers.Utilities.json(start: Long ?= 0, end: Long ?= 0 )
最后这是我的 java 脚本代码,它应该向我展示来自 Utilities.json 的测试事件
$(document).ready(function() {
$('#calendar').fullCalendar({
// put your options and callbacks here
weekNumbers: true,
weekends: false, // will hide Saturdays and Sundays
height: 420,
events: {
async: false, // tried with and without, just to make sure problem is something else
url:myJsRoutes.controllers.Utilities.json().ajax({}),
cache: false
}
})
})
使用调试器,我可以看到正在调用 Utilities.json。但我的日历视图中仍然没有任何事件。它看起来只是空的:
我做错了什么?不得不提的是,我对 Javascript 世界不是很熟悉。
【问题讨论】:
标签: javascript java playframework fullcalendar playframework-2.3