2017-06-29 343 views
0

我想添加幾天禁用服務器。這是我的代碼到目前爲止:Jquery UI Datepicker,beforeShowDay錯誤

$("#startDatePicker").datepicker({ 
     minDate: '+31', 
     maxDate: '+12M', 
     changeMonth: true, 
     showAnim: 'blind', 
     dateFormat: 'yy mm dd',   
     onSelect: function(dateText, inst) { 

      // Capture the Date from User Selection 
      var oldDate = new Date(dateText); 
      var newDate = new Date(dateText); 

      // Compute the Future Limiting Date 
      newDate.setDate(newDate.getDate() + 365); 


      // Set the Widget Properties 
      $("#endDatePicker").datepicker('option', 'minDate', oldDate); 
      $("#endDatePickerto").datepicker('option', 'maxDate', newDate); 

     } 
    }); 

    $("#endDatePicker").datepicker({ 
     minDate: '+5', 
     maxDate: '+12M', 
     changeMonth: true, 
     showAnim: 'blind', 
     dateFormat: 'yy mm dd', 
     onSelect: function(dateText, inst) { 

      // Capture the Date from User Selection 
      var endDate = new Date(dateText); 
      var startDate = new Date(dateText); 

      // Compute the Future Limiting Date 
      startDate.setDate(startDate.getDate() - 5); 

      // Set the Widget Properties 
      $("#startDatePicker").datepicker('option', 'minDate', startDate); 
      $("#startDatePicker").datepicker('option', 'maxDate', endDate); 

     } 

    }); 

選擇器工作正常,直到我添加天禁用。我從一個視圖包解析它。這是代碼。

var NewArray = []; 
var array = @Html.Raw(Json.Encode((@ViewBag.GetDates))); 
for (var i = 0; i < array.length; i++) { 
    NewArray[i] = array[i]; 
    console.log(NewArray); 

} 
var parsedDates = []; 
for (var i = 0; i < array.length; i++) { 
    var d = array[i]; 
    var unix = +d.replace(/\D/g, ''); 
    var date = new Date(unix); 
    var desDate = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate(); 
    parsedDates.push(desDate); 
} 
console.log(parsedDates); 

,我添加的日期這樣的選擇器:

beforeShowDay: function (date) { 
      var string = jQuery.datepicker.formatDate('yy mm dd', date); 
      return [parsedDates.indexOf(string) === -1]; 
     } 

揀出器看起來像這樣添加的一切,當是: enter image description here

什麼我做錯了。

回答

0

解決了它。必須重建進入beforShowDay的日期字符串。之後,一切正常。