我可能过于复杂了,但我有以下情况,我需要查看“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);
}
}
})
);
}
});
});