在我的项目中,我有一个完整的日历,可以从数据库动态加载事件。当我尝试将事件添加到日历中时。但由于我认为 httpget 方法同步问题,它对我不起作用。我无法解决问题。
this.events = [];
this.holidayList = [];
//this._holidayService.getHolidayArray().then(events => { this.events = events; });
this._holidayService.getHolidayArray().subscribe((result: any[]) => {
for (let i = 0; i < result.length; i++) {
this.events.push({ "title": result[i].title, "start": result[i].start });
//this.holidayModel = new Holiday;
//this.holidayModel.start = result[i].start;
//this.holidayModel.title = result[i].title;
//this.holidayList.push(this.holidayModel);
}
//this.events = this.holidayList;
});
this.options = {
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
selectable: true,
selectMirror: true,
select: function (arg) {
var start = arg.start.toString();
var date = start.slice(8, 10);
var year = start.slice(11, 15);
var month = start.slice(4, 7);
if (month === "Jan") month = '01';
if (month === "Feb") month = '02';
if (month === "Mar") month = '03';
if (month === "Apr") month = '04';
if (month === "May") month = '05';
if (month === "Jun") month = '06';
if (month === 'Jul') month = '07';
if (month === 'Aug') month = '08';
if (month === 'Sep') month = '09';
if (month === 'Oct') month = '10';
if (month === 'Nov') month = '11';
if (month === 'Dec') month = '12';
var fullDate = month + '/' + date + '/' + year;
$("#holiday").val(fullDate);
document.getElementById("btnCreate").innerHTML = "Save";
document.getElementById("description").innerHTML = "";
$('#description').val("");
$("#toggler")[0].click();
//calendar.unselect()
},
defaultDate: '2019-07-01',
header: {
left: 'prev,next',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: this.events
}
}
getHolidayArray() {
return this.ExecuteGet("api/HolidayCalendar/GetTitles");
}
如果我尝试
this._holidayService.getHolidayArray().then(events => { this.events = events; });
一个错误“那么在可观察类型上不存在”