2017-01-13 1 views
1

내 웹 페이지에 fullcalendar가 있습니다. 달력에 이벤트가 있습니다. dayClick 이벤트 핸들러에서 함수를 호출하고 있습니다.FullCalendar dayClick 분리하지 않은 js 이벤트

문제는 1 번 클릭하면 함수가 1 번 호출됩니다. 두 번째로 함수는 2 번 호출되고, 세 번째는 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을 사용할 수도 있지만 정확하게는 알 수 없습니다. 누구든지 이에 대한 도움을 줄 수 있습니까?

답변

3

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           
     }); 
    });     
}); 
+0

감사합니다. –

0

이벤트를 다시 연결하기 전에 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           
      }); 
     });     
    });       
}