【问题标题】:jquery Full Calendar not showing eventsjquery完整日历不显示事件
【发布时间】:2009-10-09 14:07:55
【问题描述】:

我正在使用 asp.net mvc 列出 jquery 完整日历中的事件。下面是我用来通过来自 mvc 的 json 列出事件的脚本。

$('#calendar').fullCalendar({
        theme: true,
        editable: true,
        disableDragging: true,
        disableResizing: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        events: function(start, end, callback) {
        // do some asynchronous ajax
        $.getJSON("/User/GetEvents/",
            {
                    start: dateFormat(start.getTime()),
                    end: dateFormat(end.getTime())
            },
            function(result) {
                    // then, pass the CalEvent array to the callback
                    callback(result);
            })
        },
        eventClick : function(event) {
            editEventShow(event);
        },
        dayClick : function(dayDate){
            addEventShow(dayDate, this);
        }
    });

但是上面的脚本没有在日历中显示任何事件。我在上面的脚本中做错了什么?

【问题讨论】:

  • 能否也包含来自“/User/GetEvents/”的示例输出?
  • 下面是来自 json 的响应:[{"id":1,"title":"Event from Controller","allDay":true,"date":"\/Date(-62135596800000 )\/","start":"\/Date(1255012357109)\/","end":"\/Date(1255185157109)\/","editable":true}]
  • 当我使用 firebug 调试脚本时,它显示默认日期(Fri Jan 01 1255 00:00:00 GMT+0530(印度标准时间))。如何解析 json 结果中的日期?

标签: jquery asp.net-mvc json calendar fullcalendar


【解决方案1】:

当我从 json 的事件中解析日期为:

events: function(start, end, callback) {
            // do some asynchronous ajax
            contentType:"application/json; charset=utf-8",
            $.getJSON("/User/GetEvents/",
                    {
                            start: dateFormat(start.getTime()),
                            end: dateFormat(end.getTime())
                    },
                    function(result) {
                            if(result != null)
                            {
                                for (i in result) {
                                    var calEvent = result[i];
                                    calEvent.date = new Date(parseInt(calEvent.date.replace("/Date(", "").replace(")/", ""), 10));
                                    calEvent.start = new Date(parseInt(calEvent.start.replace("/Date(", "").replace(")/", ""), 10));
                                    calEvent.end = new Date(parseInt(calEvent.end.replace("/Date(", "").replace(")/", ""), 10));
                                }
                            }

                            var calevents = result;
                            // then, pass the CalEvent array to the callback
                            callback(calevents);

                    });

        },

【讨论】:

  • 你好,prasad,很高兴你能成功。您是否也可以标记这个问题(标记:“fullcalendar”)。非常感谢!
  • 嗨 prasad,我也面临同样的问题,因为您已经对此进行了排序,请告诉我 dateFormat() 方法是什么以及 10 在 replace 方法中将做什么。请建议我如何创建我的 JSON 响应对象,以便可以在全日历中显示数据谢谢
【解决方案2】:

你也可以在服务器端格式化日期字符串

DateTime.Now.ToString("s"):

见:http://weblogs.asp.net/gunnarpeipman/archive/2010/02/03/using-fullcalendar-jquery-component-with-asp-net-mvc.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 2020-07-15
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2018-03-02
    相关资源
    最近更新 更多