我使用FullCalendar和Scheduler-从日历中删除事件时,我会将它们添加回External eventsdiv-但我需要重新初始化下面的.each函数
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true, // maintain when user navigates (see docs on the renderEvent method)
id: $(this).attr('id'),
overlap: false
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
很明显,我可以在.对话框上的一个按钮函数中抛出相同的函数来确认事件的删除,但我不想重复代码。
我尝试过这样的事情,但运气不好。
function externalEvents() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true, // maintain when user navigates (see docs on the renderEvent method)
id: $(this).attr('id'),
overlap: false
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
}
$('#external-events .fc-event').each(externalEvents());
我的思维过程是我可以运行
$('#external-events .fc-event').each(externalEvents());
每当向外部事件div.添加更多元素时
这引发一个错误TypeError: invalid 'in' operand a
调用externalEvents
时,后面有括号。您希望将其作为函数引用传递给each
。
$('#external-events .fc-event').each(externalEvents);