从数据库中格式化FullCalendar事件的JSON字符串的正确方法是什么



我正试图在MVC应用程序中呈现FullCalendar(1.5.3),如下所示:

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    titleFormat: { day: '' },
    defaultView: 'month',
    events: "/Schedule/GetCal"
});

/Schedule/GetCal得到的JSON字符串如下所示:

{id:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",projectId:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",title:"Orem City Parking Lot",start:"2012-07-11",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""},
{id:"33910A42-C5F0-42FA-AB36-C315BDDAF964",projectId:"33910A42-C5F0-42FA-AB36-C315BDDAF964",title:"Thanksgiving Point - Buster",start:"2012-07-28",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""}

它不会在页面上呈现任何事件。然而,当我这样称呼它时:

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    titleFormat: { day: '' },
    defaultView: 'month',
    events: [{id:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",projectId:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",title:"Orem City Parking Lot",start:"2012-07-11",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""},
            {id:"33910A42-C5F0-42FA-AB36-C315BDDAF964",projectId:"33910A42-C5F0-42FA-AB36-C315BDDAF964",title:"Thanksgiving Point - Buster",start:"2012-07-28",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""}
   ]
});

它按预期工作。JSON字符串的格式需要更改什么?或者,我怎么称呼它?

这篇文章帮助我弄清楚了:ASP.Net MVC、jQuery和FullCalendar

显然,对于FullCalendar 1.5.3和asp.net mvc,您需要返回一个已转换为.ToArray()List<>,然后在JSON中序列化。我一这么做,结果就如我所料出现在了日历上。

我使用alert(data)在浏览器中查看结果,而不是我在上面发布的字符串,它是

{Object},{Object}

/Schedule/GetCal脚本需要返回一个事件数组,用JSON字符串中事件集周围的方括号表示。

目前,看起来你只是返回了一个逗号分隔的事件列表,并没有按照你的预期进行解释

您的输出需要如下所示:

["0",{"allDay":","title":"去上班","id":"821","end":"2011-06-06 14:00:00"

相关内容

  • 没有找到相关文章

最新更新