Jquery fullcalendar没有显示事件

时间:2010-07-21 22:13:42

标签: javascript jquery fullcalendar jayrock

我很高兴看到像fullcalendar这样的日历插件。我正在尝试使用fullcalendar来显示每个月的事件。但事件不会显示在日历上。

我的代码是:

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult HighlightCalendar()
{
    var tasksList = new List<HighlightMonthlyEvents>();

    tasksList.Add(new HighlightMonthlyEvents
    {
        id = 1,
        EventName = "Google search",
        EventStartDate = ToUnixTimespan(DateTime.Now),
        EventEndDate = ToUnixTimespan(DateTime.Now.AddHours(4)),
        url = "www.google.com"
    });
    tasksList.Add(new HighlightMonthlyEvents
    {
        id = 1,
        EventName = "Bing search",
        EventStartDate = ToUnixTimespan(DateTime.Now.AddDays(1)),
        EventEndDate = ToUnixTimespan(DateTime.Now.AddDays(1).AddHours(4)),
        url = "www.bing.com"
    });

    var highlightDays = Jayrock.Json.Conversion.JsonConvert.ExportToString(tasksList.ToArray());

    return Json(highlightDays, JsonRequestBehavior.AllowGet);
}


 <script type="text/javascript">
 $(function () {

// FullCalendar

$('.fullcalendar').fullCalendar({
theme: true,
header: {
 left: 'today prev,next',
 center: '',
 right: ''
},
defaultView: 'month',
editable: false,
events: function (callback) {
 // do some asynchronous ajax
 contentType: "application/json; charset=utf-8",
        $.getJSON("/Test/HighlightCalendar/", null,
               function (result) {
                var calevents = new Array();
                var results = eval(result);
                eval(results.length);
                if (results != null) {
                 for (i in results) {
                  var calEvent = results[i];

                  calevents.push(calEvent)

                 }
                }
                alert(calevents.length);

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

               });
}

});

至于我的JSON,它看起来像:

[{"id":1,"allDay":false,"title":"Google search","start":1279750267,"end":1279764667,"url":"www.google.com"},{"id":2,"allDay":false,"title":"Bing search","start":1279836667,"end":1279851067,"url":"www.bing.com"}]

你怎么看待错误?

1 个答案:

答案 0 :(得分:0)

这可能与你的财产和价值的引用有关。

尝试在属性和值中包含引号并检查结果。

我没有像这样使用JSON.js就达到了同样的效果。

System.Web.Script.Serialization.JavaScriptSerializer eventListSerializer =
                                                                                    new System.Web.Script.Serialization.JavaScriptSerializer();
                string eventListJSON = eventListSerializer.Serialize(addevList);