【问题标题】:Events not shown in fullcalendar (play framework)全日历中未显示的事件(播放框架)
【发布时间】: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


    【解决方案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"
            })
        })
    

    现在一切正常

    【讨论】:

      猜你喜欢
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多