何かを機能させるのに苦労しています - 以下のように「Uncaught TypeError: Cannot read property '0' of undefined」というエラーが表示され、その理由がわかりません!
空室状況と季節 (低、高など) を示すために、休日のコテージのサイトで jQuery UI の日付ピッカーを使用しようとしています。日付の予約があるかどうかを確認する datePicker イベントとしての機能があり、そうでない場合は、どのシーズンにいるかを確認するために出かけます (ピークシーズン以外では、月曜日または金曜日に予約を行うことができます.繁忙期は金曜日のみです。)
cms を使用して (ループを介して) いくつかの日付配列を生成し、カレンダーを作成するときにそれを反復できるため、javascript は少し冗長です。
配列は次のようになります。
<script>
//Peak Season 1 2011
var ps1 = new Date('June 17, 2011');
var pe1 = new Date('September 2, 2011');
//Peak Season 2 2011
var ps2 = new Date('December 19, 2011');
var pe2 = new Date('January 6, 2012');
// season start and end date arrays
var peakStart = new Array(ps1,ps2);
var peakEnd = new Array(pe1,pe2);
// Bookings
//Mr & Mrs Smith
var cbs1 = new Date('May 27, 2011');
var cbe1 = new Date('June 5, 2011');
//Mr & Mrs Jones
var cbs2 = new Date('September 1, 2011');
var cbe2 = new Date('September 18, 2011');
var cottageStart = new Array(cbs1,cbs2);
var cottageEnd = new Array(cbe1,cbe2);
// last date of season - don't book past here
var lastDate = '01/06/2012';
</script>
beforeShowDate イベントから呼び出して、予約配列に対してカレンダーの日付をチェックする次の関数があります。
$('#cottageCal').datepicker({
minDate: '0d',
maxDate: lastDate,
beforeShowDay: function(date) {
$.each(cottageStart, function(key, value) {
//alert (((date >= value) && (date <= value)) ? 'booked' : 'notbooked');
if ((date >= value) && (date <= value)) {
return [false, 'booked'];
} else {
return checkPeak(date);
}
});
}
});
最後に、ここから呼び出される checkPeak 関数は次のようになります。
var checkPeak = function(date) {
var day = date.getDay();
var month = date.getMonth();
$.each(peakStart, function(key, value) {
if ((date > value) && (date < value)) {
/* december peak bookings on monday*/
if (month != 11) {
return [(day == 5), ''];
} else {
return [(day == 1), ''];
}
}
if (month == 0) {
return false;
} else {
// it's not during a peak period
return [(day == 1 || day == 5), ''];
}
});
}
ここで根本的に間違ったことをしているに違いありませんが、何がわかりません!