2013-05-21 3 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' 
       } 
      ] 
     }) 
    }); 

вебсервис:

[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

Правильный формат JSON для Fullcalendar что-то вроде этого:

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

Спасибо, Энрике, но я отработал его по-другому. Я нашел хороший пример, и он работает для меня. Пример: https://code.google.com/p/fullcalendar-asp-net/ – jarek

+0

Без проблем, хорошо для вас;) –

Смежные вопросы