How to call events on clicking prev and next button?

后端 未结 11 1681
天涯浪人
天涯浪人 2020-12-24 07:26

In jQuery fullcalendar we have previous and next buttons. How can we call some events on click of these buttons?

11条回答
  •  难免孤独
    2020-12-24 08:14

    When the next and previous buttons are clicked, the events function is called. Here is an example to load data for the current year:

    $(document).ready(function() {
      loadCal();
    });
    
    function loadCal() {
    
      var current_url = '';
      var new_url = '';
    
      $('#calendar').fullCalendar({
    
        // other options here...
    
        events: function(start, end, callback) {
    
          var year = end.getFullYear();
    
          new_url = '/api/user/events/list/' + id + '/year/' + year;
    
          if (new_url != current_url) {
    
            $.ajax({
              url: new_url,
              dataType: 'json',
              type: 'POST',
              success: function(response) {
    
                current_url = new_url;
                user_events = response;
    
                callback(response);
              }
            })
          } else {
            callback(user_events);
          }
        }
      })
    }
    

    When you retrieve the results in a query, make sure you include at least the last 10 days from the previous year and the first 10 days from the next year.

提交回复
热议问题