我使用fullcalendar作为插件来做一些事情。我正按照文档中的说明初始化日历:
select c,count(*)
from ( select c1 as c from t
union all select c2 from t
union all select c3 from t
) t
group by c
;
我需要更改传递给eventClick属性的函数的范围,因为我的_onEventClick函数将使用明显不在click事件发生的除法范围内的函数。这是_onEventClick函数:
_initializeCalendar: function() {
let me = this;
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listWeek'
},
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
events: me._createEvents(me.releaseStore),
eventClick: me._onEventClick
});
},
那么,有没有办法将全局范围传递给fullcalendar的eventClick属性?谢谢。
答案 0 :(得分:0)
解决方案是在将函数传递给object属性时使用bind。 所以在代码中它看起来像这样:
clickEvent: me._onEventClick.bind(me)
此处“me”在_initializeCalendar中设置为“this”,因此“this”具有全局范围。