所以我在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
答案 0 :(得分:0)
好的,我已成功解决了这个问题。通过异步调用解决了:
'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
}