【问题标题】:jQuery FullCalendar Plugin not Showing EventsjQuery FullCalendar 插件不显示事件
【发布时间】:2011-11-02 04:41:31
【问题描述】:

我在 CodeIgniter 应用程序中使用FullCalendar plugin。我正在使用 GET 请求服务器端检索事件对象,并且使用与带有回调的 events as a function example 类似的方法,事件不会显示在日历上。我已验证 GET 请求正确返回 json。

这是我的请求返回的 json...

[{"id":"1","title":"2011 Acura Integra (1)","start":1313996400,"color":"red"}, {"id":"15","title":"2011 Acura Integra (1)","start":1314774000,"color":"red"}]

我的电话如下……

    var year = $("#year").text();
    var month = $("#month").text();

    $maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
        year: year,
        month: month -1,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: ''
        },
        editable: true,
        disableResizing: true,
        events: function(start, end, callback) {
            var start_timestamp = Math.round(start.getTime() / 1000);
            var end_timestamp = Math.round(end.getTime() / 1000);
            var url = "/tripsys/new_admin/vehicles/get_maintenance_schedule_data/" + start_timestamp + "/" + end_timestamp;

            $.get(url, function(events) {
                callback(events);
            });
        }
    });

奇怪的是,之前的调用正确地获取了 json,并且回调似乎处理了事件,因为如果我调用 .fullCalendar('clientEvents'),它会显示我传递给 events 方法的 json,但它们不会呈现。

但是,如果我将这个相同的 json 直接传递到我的初始 FullCalendar 调用中,事件会呈现...

    var year = $("#year").text();
    var month = $("#month").text();

    $maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
        year: year,
        month: month -1,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: ''
        },
        editable: true,
        disableResizing: true,
        events: [
            {"id":"1","title":"2011 Acura Integra (1)","start":1313996400,"color":"red"},
            {"id":"15","title":"2011 Acura Integra (1)","start":1314774000,"color":"red"}
        ]
    });

有人知道为什么第一个示例没有在我的日历上呈现事件吗?

【问题讨论】:

    标签: javascript jquery fullcalendar


    【解决方案1】:

    原来问题是我用 $.get 而不是 $.getJSON 请求数据引起的

    这是正确的调用...

        var year = $("#year").text();
        var month = $("#month").text();
    
        $maintenance_schedule_calendar_table = $("#vehicles_maintenance_schedule_calendar").fullCalendar({
            year: year,
            month: month -1,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: ''
            },
            editable: true,
            disableResizing: true,
            events: function(start, end, callback) {
                var start_timestamp = Math.round(start.getTime() / 1000);
                var end_timestamp = Math.round(end.getTime() / 1000);
                var url = "/tripsys/new_admin/vehicles/get_maintenance_schedule_data/" + start_timestamp + "/" + end_timestamp;
    
                $.getJSON(url, function(events) {
                    callback(events);
                });
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多