FullCalendar dayClick js事件没有分离
FullCalendar dayClick js event not detaching
我的网页上有一个完整的日历。日历有事件。在 dayClick
事件处理程序上,我正在调用一个函数。
问题是第 1 次单击日期框时函数被调用 1 次。第 2 次函数被调用 2 次,第 3 次 3 次..等等。
我猜是当天点击事件没有分离的问题。但我无法解决。
代码:
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
defaultView: 'month',
editable: false,
eventClick: function (event) {
if (event.url) {
window.open(baseUrl + event.url);
return false;
}
},
dayClick: function (date, allDay, jsEvent, view) {
var dateString = '';
dateString = moment(date, 'YYYY-MM-DD').format().split('T')[0];
$('#popup').modal('toggle');
$('#popup').on('shown.bs.modal', function () {
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
}
});
我不确定如何分离此事件。可能是通过使用 off
或 unbind
,但不知道具体如何。
任何人都可以提供一些帮助吗?
你应该使用off
方法。
$('#popup').on('shown.bs.modal', function () {
$('#popup').off('shown.bs.modal');
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
在再次附加事件之前尝试使用 jQuery.unbind()
。
dayClick: function (date, allDay, jsEvent, view) {
var dateString = '';
dateString = moment(date, 'YYYY-MM-DD').format().split('T')[0];
$('#popup').modal('toggle');
$('#popup').unbind("shown.bs.modal").on('shown.bs.modal', function () {
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
}
我的网页上有一个完整的日历。日历有事件。在 dayClick
事件处理程序上,我正在调用一个函数。
问题是第 1 次单击日期框时函数被调用 1 次。第 2 次函数被调用 2 次,第 3 次 3 次..等等。
我猜是当天点击事件没有分离的问题。但我无法解决。
代码:
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
defaultView: 'month',
editable: false,
eventClick: function (event) {
if (event.url) {
window.open(baseUrl + event.url);
return false;
}
},
dayClick: function (date, allDay, jsEvent, view) {
var dateString = '';
dateString = moment(date, 'YYYY-MM-DD').format().split('T')[0];
$('#popup').modal('toggle');
$('#popup').on('shown.bs.modal', function () {
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
}
});
我不确定如何分离此事件。可能是通过使用 off
或 unbind
,但不知道具体如何。
任何人都可以提供一些帮助吗?
你应该使用off
方法。
$('#popup').on('shown.bs.modal', function () {
$('#popup').off('shown.bs.modal');
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
在再次附加事件之前尝试使用 jQuery.unbind()
。
dayClick: function (date, allDay, jsEvent, view) {
var dateString = '';
dateString = moment(date, 'YYYY-MM-DD').format().split('T')[0];
$('#popup').modal('toggle');
$('#popup').unbind("shown.bs.modal").on('shown.bs.modal', function () {
AsyncFn().done(function (result) {
AnotherAsyncFn(function () {
SomeFunction(); //This function gets called multiple times
});
});
});
}