有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

fullcalendar(播放框架)中未显示的javascript事件

我正在使用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
            }
        })
    })

使用调试器,我可以看到实用程序。正在调用json。但我的日历视图中仍然没有任何事件。它看起来只是空的: enter image description here

我做错了什么?我必须提到,我对Javascript世界不是很熟悉


共 (1) 个答案

  1. # 1 楼答案

    我发现传递给我的Utilities.json的参数不是作为Long解析的,但它们必须是String。所以我改变了主意

    public static Result json(Long start, Long end) throws ParseException {
    

    public static Result json(String start, String end) throws ParseException {
    

    并将我的路线更改为:

    GET           /events.json                              controllers.Utilities.json(start: String, end: String)
    

    我还意识到我不需要Javascript路由器,因此我将Javascript代码更改为:

        $(document).ready(function() {
    
            $('#calendar').fullCalendar({
                // put your options and callbacks here
                weekNumbers: true,
                weekends: false, // will hide Saturdays and Sundays
                height: 420,
                events: "/events.json"
            })
        })
    

    现在一切都很顺利