2012-07-06 16 views
2

我使用的是jQuery Fullcalendar plugin,它在月視圖中效果很好。我現在玩弄周視圖。問題在於,當我每週來回移動時,它似乎只在本週開始的新月份重新開始活動。因此,如果周視圖是一個月的1/2和新月的1/2(例如,2012年7月的最後一週在7月29日開始,但在8月4日結束),那麼它會贏得' t請求重新獲取事件。當我再次點擊前進時,它只會重新查看事件,而我正處於(8月5日 - 8月11日)的一週。爲什麼jquery FullCalendar在跨越一個月的時候要求在周視圖中重新獲取事件?

問題是我只在服務器上加載了特定月份的事件(所以我不會在下個月的前幾天加載)。查看我的月份和月份的傳遞位置,以便我的服務器知道要查詢哪些數據。

$.ajax({ 
    url: '/EventCalendar/GetCalEvents/', 
    dataType: 'json', 
    data: { 
    month: $('#calendar').fullCalendar('getDate').getMonth() + 1, 
    year: $('#calendar').fullCalendar('getDate').getUTCFullYear(), 
    }, 
    success: function (data) { 
    callback(data.Events); 
    } 
}); 

這是否由設計,我真的應該返回下個月的第一週的事件,或者這是一個錯誤?爲什麼沒有完整的日曆觸發事件請求?

+0

良好的漁獲!你嘗試過不同的weekMode嗎?像'weekMode:'liquid''或'weekMode:'variable''? – ganeshk 2012-07-06 14:05:07

回答

1

您是否嘗試過使用$('#calendar').fullCalendar('getView')

這將返回一個包含開始和結束時間的view object。您可以傳遞這些值,並返回視圖顯示期間發生的所有事件,而不是傳遞單個月份和年份。

更好的是,您可以使用完整日曆的能力來拉動directly from a json feed。開始值和結束值自動作爲url參數傳遞,當視圖更改時(例如,從一週到另一週,從每月到每天,每天或從任何主視圖移動時),都會更新事件。

編輯:重新閱讀此之後,您可能還想嘗試將lazyFetching也設置爲false。

1

這是因爲您的默認視圖設置爲。當日歷加載時,它會加載整個月份的事件。現在當你切換到周視圖它不會加載事件,因爲它已經有整個月的事件。 FullCalendar智能獲取事件。 如果設置默認視圖周或天是這樣的:

defaultView: 'agendaWeek', 

你會看到它會單獨加載事件每星期。 我希望這可以幫助。謝謝

1

而不是定義自己的$.ajax(...)功能和設置您自己的範圍(通過解析.fullCalendar('getDate'))使用內置的數據源。然後,您將獲得可見的日曆範圍作爲您的ajax服務器端事件獲取的輸入。

初始化時設置源.fullCalendar(...)。請參閱setting EventSource $.ajax(...) options to fetch JSON calendar event data上的文檔。

$('#calendar').fullCalendar({ 
    // Put your other fullCalendar options here too 
    eventSources: [ 
     { 
      url: '/EventCalendar/GetCalEvents/', 
      dataType: 'json', 
      error: function(jqXHR, textStatus, errorThrown) { 
       // Logging any error that occured fetching the events 
       if(console && console.error){ console.error(arguments); } 

       alert("Couldn't fetch events, check the javascript console error log."); 
      } 
     } 
    ] 
}); 

/EventCalendar/GetCalEvents/請求將包含兩個UNIX timestamp(秒自1970年以來):

  • start:第一個可見的天的開始(含)
  • end:最後一個可見一天結束(排斥)
  • _:用作ajax cache busting technique一個可選的非靜態數。只要忽略這一點。

實例的請求到服務器

/EventCalendar/GetCalEvents/?start=1262332800&end=1265011200&_=1263178646 

只是解析日期值,並返回重疊start任何部分的日曆事件 - end範圍。

0

我認爲它在數據沒有錯傳遞到背面end..Data傳遞來說,這是我做過什麼......我是新來Fullcalendar ......這對我來說是什麼工作? 。

eventSources: 
     [ 

      // your event source 
       { 

        url: '/ajax-load-holidays',// use the `url` property 
        type: 'POST', 
        datatype: "JSON", 
        data : function() 
        { // a function that returns an object 
         var date = new Date($('#calendar').fullCalendar('getDate')); 
         month_integer = date.getMonth(); 
         year_integer = date.getFullYear(); 
          return { 
           month: month_integer, 
           year: year_integer 
          } 
        }, 

        error: function() { 
         alert('there was an error while fetching eventsin hol!'); 
        }, 
        color: 'yellow', // a non-ajax option 
        textColor: 'blue' // a non-ajax option 

       }, 


     ], 
    eventRender: function(event, element, view) { 
     // lets test if the event has a property called holiday. 
     // If so and it matches '1', change the background of the correct day 

     if (event.holiday == '1') { 
      var dateString1 = event.start.format("YYYY-MM-DD"); 

      $(view.el[0]).find('.fc-day[data-date=' + dateString1 + ']') 
       .css('background-color', '#FAA732','.fc-time','disable'); 
     } 

    } 

//這是我的控制器......我在laravel這樣做(MVC-庫)

public function LoadHoliday(Request $request) 
{ 



    $this->year = $request['year']; 
    $month = $request['month']; 


     $month++; 
     $this->month=$month; 

$Rowdata1 = ($this->holidayFixed->getValueMonth("monthOfTheYear",$this-month)); $Rowdata2 = $this->holidayMovable->getValueMonth("monthID",$this->month);

$x=0; 
    $data1[] = 0; 
    $data2[] = 0; 
    if($Rowdata1==null && $Rowdata2==null) 
    { 
     return 0; 
    } 
    else { 


     foreach($Rowdata1 as $value){ 

      $mon = $value->monthOfTheYear; 
      $day = $value->dayOfTheMonth; 



      $dateD = $this->year. '-' . $mon . '-' . $day; 


      $data1[$x] = [ 
       'title' => $value->description, 
       'start' => $dateD, 
       'holiday' => '1' 

      ]; 
      $x++; 

     } 

     foreach($Rowdata2 as $value){ 
      $year = ($value->yearID); 
      $mon = $value->monthID; 
      $day = ($value->dateID); 

      $dateD = $year . '-' . $mon . '-' . $day; 



      $data2[$x] = [ 
       'title' => $value->description, 
       'start' => $dateD, 
       'holiday' => '1' 

      ]; 
      $x++; 

     } 
     if($data1==['0'] && $data2==['0']) 
     { 

      return 0; 
     } 
     elseif($data1==['0']) 
     { 

      return $data2; 
     } 
     elseif($data2==['0']) 
     { 

      return $data1; 
     } 
     else 
     { 
      unset($data2['0']); 
      $data3 = array_merge($data1, $data2); 

      return $data3; 

     } 


    } 


} 

相關問題