我正在尝试将 PHP 数组转换为 jQuery 的 datetimepicker 以禁用某些日期的 javascript 数组。但我似乎无法在互联网上找到正确的答案。我正在为我的项目使用 Zend Framework。
<?php
$ConvertDateBack = Zend_Controller_Action_HelperBroker::getStaticHelper('ConvertDate');
$disabledDaysRange = array();
foreach($this->reservedDates as $dates) {
$date = $ConvertDateBack->ConvertDateBack($dates->reservation_date);
$disabledDaysRange[] = $date;
}
?>
<script>
var disabledDaysRange = $disabledDaysRange ???? Please Help;
$(function() {
function disableRangeOfDays(d) {
for(var i = 0; i < disabledDaysRange.length; i++) {
if($.isArray(disabledDaysRange[i])) {
for(var j = 0; j < disabledDaysRange[i].length; j++) {
var r = disabledDaysRange[i][j].split(" to ");
r[0] = r[0].split("-");
r[1] = r[1].split("-");
if(new Date(r[0][2], (r[0][0]-1), r[0][1]) <= d && d <= new Date(r[1][2], (r[1][0]-1), r[1][1])) {
return [false];
}
}
}else{
if(((d.getMonth()+1) + '-' + d.getDate() + '-' + d.getFullYear()) == disabledDaysRange[i]) {
return [false];
}
}
}
return [true];
}
$('#date').datepicker({
dateFormat: 'dd/mm/yy',
beforeShowDay: disableRangeOfDays
});
});
</script>