2013-05-21 86 views
0

我是新的查询,我有fullcalendar的问题(http://arshaw.com/fullcalendar/)。我想根据其类型对事件进行着色。jquery fullcalendar与彩色事件

JS:

$(document).ready(function() { 
     $('#fullcal').fullCalendar({ 
      allDayDefault: false, 
      defaultView: 'agendaWeek', 
      eventSources: [ 
       { 
        url: 'WS.asmx/GetSchedulerEvents', 
        type: 'POST', 
        data: { 
         taskType: 'TODO' 
        }, 
        color: 'red', 
        textColor: 'black' 
       }, 
       { 
        url: 'WS.asmx/GetSchedulerEvents', 
        type: 'POST', 
        data: { 
         taskType: 'COMPLETED' 
        }, 
        color: 'blue', 
        textColor: 'white' 
       } 
      ] 
     }) 
    }); 

web服务方法:

[WebMethod] 
    public List<SchedulerEvent> GetSchedulerEvents(string taskType) 
    { 
     List<SchedulerEvent> events = new List<SchedulerEvent>(); 

     if (taskType == "TODO") 
     { 
      events.Add(new SchedulerEvent(
       2, 
       "EventName 1", 
       new DateTime(2013, 05, 20, 10, 00, 00).ToString(), 
       new DateTime(2013, 05, 20, 10, 00, 00).AddHours(4).ToString() 
      )); 
     } 
     else if (taskType == "COMPLETED") 
     { 
      events.Add(new SchedulerEvent(
       1, 
       "EventName 2", 
       new DateTime(2013, 05, 21, 11, 00, 00).ToString(), 
       new DateTime(2013, 05, 21, 11, 00, 00).AddHours(3).ToString() 
      )); 
     } 

     return events; 
    } 

请求:

taskType=TODO&start=1368914400&end=1369519200 

and 

taskType=COMPLETED&start=1368914400&end=1369519200 

响应:

<?xml version="1.0" encoding="utf-8"?> 
<ArrayOfSchedulerEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"> 
    <SchedulerEvent> 
    <EventId>1</EventId> 
    <EventName>EventName 2</EventName> 
    <StartDate>2013-05-21 11:00:00</StartDate> 
    <EndDate>2013-05-21 14:00:00</EndDate> 
    </SchedulerEvent> 
</ArrayOfSchedulerEvent> 

and 

<?xml version="1.0" encoding="utf-8"?> 
<ArrayOfSchedulerEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"> 
    <SchedulerEvent> 
    <EventId>2</EventId> 
    <EventName>EventName 1</EventName> 
    <StartDate>2013-05-20 10:00:00</StartDate> 
    <EndDate>2013-05-20 14:00:00</EndDate> 
    </SchedulerEvent> 
</ArrayOfSchedulerEvent> 

我的问题是:为什么请求和响应不是json格式?

感谢

回答

0

为Fullcalendar正确的JSON格式是这样的:

JSON FORMAT FEED 
[ 
{ 
    "title" : "New shift", 
    "start" : "2010-10-25 09: 30: 00 +0100", 
    "end" : "2010-10-25 13: 30: 00 +0100", 
    "allDay" : false 
}, 
{ 
    "title" : "New shift", 
    "start" : "2010-10-25 08: 00: 00 +0100", 
    "end" : "2010-10-25 14: 00: 00 +0100", 
    "allDay" : false 
}, 
{ 
    "title" : "New shift", 
    "start" : "2010-10-25 08: 00: 00 +0100", 
    "end" : "2010-10-25 14: 00: 00 +0100", 
    "allDay" : false 
}, 
{ 
    "title" : "New shift", 
    "start" : "2010-10-27 08: 00: 00 +0100", 
    "end" : "2010-10-27 13: 30: 00 +0100", 
    "allDay" : false 
} 
] 

这是从另一个问题,我不记得是哪一个,所以也许它可以帮助你检查你的。

+0

非常感谢Henrique,但我以不同的方式解决了这个问题。我发现了一个很好的例子,它适用于我。例如:https://code.google.com/p/fullcalendar-asp-net/ – jarek

+0

没问题的队友,对你有好处;) –