我正在 .net 8 核心项目中使用完整日历和 rrule 插件。我正在尝试将过期日期添加到重复事件中。这是我的代码
events: function (fetchInfo, successCallback, failureCallback) {
$.ajax({
url: "@Url.Action("GetCalendarEvents", "CalendarEvents")",
method: 'GET',
dataType: 'json',
success: function (response) {
var events = [];
$.each(response, function () {
var e = "'2024-11-05T13:30:00','2024-11-07T13:30:00'";
var temp = '';
if (this.dtstart !== null) {
temp = this.dtstart.replace(/-/g, '');
temp = temp.replace(/:/g, '');
var r = 'DTSTART:' + temp + '\nRRULE:' + this.rrule;
}
events.push({
title: this.title,
start: this.event_start,
end: this.event_end,
backgroundColor: this.color,
borderColor: this.color,
textColor: '#ffffff',
rrule: r,
extendedProps: {
description: this.description,
start: this.start,
end: this.end,
color: this.color,
start_time: this.start_time,
end_time: this.end_time,
recurring: this.recurring,
id: this.id
}
//exdate: [e]
//exdate: ['2024-11-05T13:30:00', '2024-11-07T13:30:00']
});
});
successCallback(events);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Error: ' + textStatus);
//failureCallback();
}
});
}
如果我通过 exdate: ['2024-11-05T13:30:00', '2024-11-07T13:30:00'],一切正常。但如果我将 exdate 作为这样的变量传递
var e = "'2024-11-05T13:30:00','2024-11-07T13:30:00'";
exdate: [e]
我收到 TypeError: Cannot read properties of null (reading 'timeZoneOffset') 错误。知道我犯了什么错误吗?
我使用变量的原因是因为 exdates 将来自对数据库的 ajax 调用。
我相信出现此问题是因为 exdate 需要是日期字符串数组,而无需在它们周围添加额外的引号。 Var e 在变量周围使用双引号,在每个日期周围使用单引号。您是否可以创建这样的变量: var e = ['2024-11-05T13:30:00', '2024-11-07T13:30:00']; ?