2015-08-25 22 views
1

我在我的查看頁面有完整的日曆控制,我想在移動到prev/next week時將周開始日期傳遞給控制器​​。所以,我用它來與以下:將日期傳遞給控制器​​時移動到上一個/下一個FullCalendar jquery

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

     events: function (start, end, callback) { 
      $.get('events/get', function (result) { 
       callback(result); 
      });   

      startDate = $('#calendar').fullCalendar('getDate').startOf('week'); 
      window.location.href = "/timesheet/index?selectDate=" + convertDate(startDate);   
     } 
    }); 

但現在它不斷地重新加載頁面,在這裏無法看到.. 誰能幫我做這件事..提前 謝謝..

回答

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

     events: function (start, end, callback) { 
      $.get('events/get', function (result) { 
       callback(result); 
      });   
     } 
    }); 

    $('.fc-prev-button').click(function() { 
     startDate = $('#calendar').fullCalendar('getDate').startOf('week'); 
     window.location.href = "/TimesheetModels/EmpTimesheet?selectDate=" + convertDate(startDate); 
    }); 
    $('.fc-next-button').click(function() {; 
     startDate = $('#calendar').fullCalendar('getDate').startOf('week'); 
     window.location.href = "/TimesheetModels/EmpTimesheet?selectDate=" + convertDate(startDate); 
    }); 

    var stdate = $('#startDateCalendar').val(); 
    var testdate = new Date(stdate); 
    if (Date.parse(testdate)) { 
     $('#calendar').fullCalendar('gotoDate', testdate); 
    } 
    else{} 
0

其實location.href會一次又一次地調用自己。因此,這是遞歸的過程,擺脫這個過程中,你需要做一些靜態的(不變量),但網絡存儲像localStorage爲EGS的,

.... 
startDate = $('#calendar').fullCalendar('getDate').startOf('week'); 
if(!localStorage.getItem('isConvertedDate')){ // if key is not set and first time load 
    localStorage.setItem('isConvertedDate',1); //set key, so that next time it will not refresh the page again 
    window.location.href = "/timesheet/index?selectDate=" + convertDate(startDate); 
} else { 
    localStorage.removeItem('isConvertedDate');//remove if added 
} 
.... 
相關問題