所以我在 MeteorJS 应用程序中有一个日历,当从外部添加到日历时,它会显示,但仅在重新加载后显示。所以我的问题是refetchEvents
没有按照我在该控制器的事件块中的以下代码运行:
'submit #add-event': function(event, template) {
var title = event.target.title.value;
var start = event.target.startDate.value;
var end = event.target.endDate.value;
var invited = $('select[name="invited"]').val();
var matter = event.target.matter.value;
var where = event.target.where.value;
var description = event.target.description.value;
params = {
title: title,
start: start,
end: end,
invited: invited,
matter: matter,
where: where,
description: description
}
Meteor.call('addEvent', params);
toastr.success('Event created!');
$('#addEvent').modal('hide');
$('#calendar').fullCalendar( 'refetchEvents' );
event.preventDefault();
}
此模板的rendered
回调中也发生了同样的情况(在显示新事件之前需要重新加载):
dayClick: function(date, allDay, jsEvent, view) {
// Insert the day someone's clicked on
var invited = [];
invited.push(Meteor.user().username);
params = {
title: 'New Event',
start: date,
end: date,
invited: invited,
matter: null,
where: null,
description: null
}
Meteor.call('addEvent', params);
// CalEvents.insert({title:'New Event',start:date,end:date, allDay: false});
// Refreshes the calendar
$('#calendar').fullCalendar( 'refetchEvents' );
}
关于如何让refetchEvents
工作的任何想法?
我正在使用这个完整的日历包 - https://atmospherejs.com/mrt/fullcalendar
好的,
我已经设法解决了这个问题。已改为通过执行异步调用来解决:
'submit #add-event': function(event, template) {
var title = event.target.title.value;
var start = event.target.startDate.value;
var end = event.target.endDate.value;
var invited = $('select[name="invited"]').val();
var matter = event.target.matter.value;
var where = event.target.where.value;
var description = event.target.description.value;
params = {
title: title,
start: new Date(start),
end: new Date(end),
invited: invited,
matter: matter,
where: where,
description: description
}
Meteor.call('addEvent', params, function(error, result) {
if (!error) {
toastr.success('Event created!');
$('#addEvent').modal('hide');
$('#calendar').fullCalendar( 'refetchEvents' );
} else {
toastr.error(error.reason);
}
});
event.preventDefault();
}
和
dayClick: function(date, allDay, jsEvent, view) {
// Insert the day someone's clicked on
var invited = [];
invited.push(Meteor.user().username);
params = {
title: 'New Event',
start: date,
end: date,
invited: invited,
matter: null,
where: null,
description: null
}
Meteor.call('addEvent', params, function(error, result) {
$('#calendar').fullCalendar( 'refetchEvents' );
});
// CalEvents.insert({title:'New Event',start:date,end:date, allDay: false});
// Refreshes the calendar
}