2013-05-01 74 views
0

我想一次只加載一個月的事件。首先,在一頁中顯示一個月的事件,按下一個或上一個按鈕時,通過Web服務(C#)從數據庫中顯示該月的事件。我怎樣才能做到這一點?fullcalendar:按下next或prev按鈕時調用web服務函數

我也想從一個月內獲取數據,我想將選定年份,月份值發送到Web服務,以便它可以發送特定月份的數據。

我當前的jQuery代碼是:

jQuery(document).ready(function() { 
     $.ajax({ 
      type: "POST", 
      contentType: "application/json", 
      url: "FullcalenderwithWebservice.asmx/GetEvents", 
      dataType: "json", 
      success: function (data) { 
       $("div[id=loading]").hide(); 
       $("div[id=fullcal]").show(); 
       $('div[id*=fullcal]').fullCalendar({ 
        header: { 
         left: '', 
         center: 'title', 
         right: 'today prev,next' 
        }, 
        editable: false, 
        events: $.map(data.d, function (item, i) { 
         var event = new Object(); 
         event.id = item.EventID; 
         event.start = new Date(item.StartDate); 
         event.title = item.EventName; 
         event.className = item.className.toString() 
         return event; 
        }) 
       }); 

      }, 
      error: function (XMLHttpRequest, textStatus, errorThrown) { 
       debugger; 
      } 
     }); 

    }); 

$('.fc-button-prev span').click(function(){ 
    alert('prev is clicked, do something'); 
}); 

不工作。

回答

0

您可能想要使用viewdisplay例如 viewDisplay:function(view){var next = view.title;警報(未來); }

在這裏,我正在使用該事件,並從web服務獲取下一批數據並進行呈現。

$(document).ready(function() { 

var calendar = $('#calendar').fullCalendar({ 
    header: { 
     left: 'prev,next today', 
     center: 'title', 
    }, 


    eventSources: [ getCalData() ], 
    header: { 
     left: 'prev,next today', 
     center: 'title', 
     right: '' 
    }, 
    viewDisplay: function (view) { 
     $('#calendar').fullCalendar('removeEvents'); 
     $('#calendar').fullCalendar('addEventSource', getCalData()); 
     $('#calendar').fullCalendar('rerenderEvents'); 
    } 
    }); 
}); 


function getCalData() { 

var source = [{}]; 
$.ajax({ 
    async: false, 
    url: '/mysite/GetWeekData', 
    data: { myParam: $('#calendar').fullCalendar('getView').visStart }, 
    success: function (data) { 
     $(data).each(function() { 
      source.push({ 
       title: $(this).attr('title'), 
       start: $(this).attr('start'), 
      }); 
     }); 
    }, 
    error: function() { 
     alert('could not get the data'); 
    }, 
}); 
return source; 
} 
相關問題