これは複雑すぎるかもしれませんが、「ResourceScheduleType」が何らかの数値に等しいかどうかを確認する必要がある次のような状況があります。コード内のコメントは、私がやろうとしていることを最もよく表していると思います。何らかの理由で、「一致する」変数が必要なプロパティを提供しません.jQuery grep ピースの使用もやめたいと思います。
class MyCalendarVM {
CalendarPoints: MyCalendarPoints[];
}
class MyCalendarPoints {
ResourceScheduleType: number;
aDate: string;
}
class MyType {
MyName: string;
}
$(document).ready(() => {
$.get("/Calendar/GetMonthCalendar", null, (data: MyCalendarVM) => {
if (data.CalendarPoints.length == 0) {
(<any>$('#date')).datepicker();
} else {
$(<any>data.CalendarPoints).each(
(<any>$("#date")).datepicker({
beforeShowDay: function (date) {
var result = new Array(true, '', null);
var matching = <MyCalendarPoints[]>$.grep(data.CalendarPoints, function (event) {
return event.Date.valueOf() === date.valueOf();
}, false);
//TODO: make determination for blue or yellow dot
if (matching.length) {
var classes = "";
// if matching.ResourceScheduleTypeId == 3
// classes += "yellowDot";
// if matching.ResourceScheduleTypeId == 1 || 2 || 9
// classes += " blueDot";
result = [true, classes, null];
}
return result;
},
onSelect: function (dateText) {
var date,
selectedDate = new Date(dateText),
i = 0,
event = null;
while (i < data.CalendarPoints.length && !event) {
date = data.CalendarPoints[i].aDate;
if (selectedDate.valueOf() === date.valueOf()) {
event = data.CalendarPoints[i];
}
i++;
}
if (event) {
alert(event.Title);
}
}
})
);
}
});
});