简体   繁体   English

jQuery Full Calendar更新/过滤日历

[英]jQuery Full Calendar update/filter calendar

I am trying to implement client side filtering using fullcalendar.js. 我正在尝试使用fullcalendar.js实现客户端过滤。 I can render the calendar initially using: 我可以首先使用以下方式呈现日历:

function getCalendar($venue) {

    $('#calendar').fullCalendar({

        eventSources: [
           {
              url: ajaxUrl,
              type: "GET",
              dataType: "json",
              data: {
                  action: 'loop_events_output',
                  venue: $venue,
              },

             beforeSend: function() {
                 $("#calendar").LoadingOverlay("show", {
                     color: "rgba(51,51,51,0.8)",
                 });    
             },
             complete: function() {                
                 $("#calendar").LoadingOverlay("hide");
             },

             error: function() {
                alert('there was an error while fetching events!');
             },
           }
        ]


    }); 
}

// execute on load
getCalendar('townsville');

Now I want to be able to update the calendar based on a checkbox input, here is the second part of my code: 现在,我希望能够基于复选框输入来更新日历,这是代码的第二部分:

// execute when using filters
$('.calendar-controls input').change(function(){
    if (this.checked) {
        var checkedVal = $(this).val();

        $("#calendar").fullCalendar('removeEvents');
        getCalendar(checkedVal);
        $('#calendar').fullCalendar('refetchEvents')
    }
});

But I can see from the XHR requests that the request url is not changing and remain as: /wp-admin/admin-ajax.php?action=loop_events_output&venue=townsville&start=2016-07-31&end=2016-09-11&_=1472626202164 但是我可以从XHR请求中看到请求的URL并未更改,并保持为:/wp-admin/admin-ajax.php?action=loop_events_output&venue=townsville&start=2016-07-31&end=2016-09-11&_=1472626202164

Any help appreciated. 任何帮助表示赞赏。

OK so I ended up figuring this one out. 好的,所以我最终弄明白了这一点。 Essentially the way fullcalendar works is that it takes the events object on load and will continue using that object on future renders unless that object is reset. 从本质上讲,fullcalendar的工作方式是加载事件对象,并在将来的渲染中继续使用该对象,除非重置该对象。 So they way I did it was to change my full calendar function to: 所以他们这样做的方式是将我的完整日历功能更改为:

function getCalendar() {

    $('#calendar').fullCalendar({

        events: source,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: ''
        },
        eventRender: function (event, element) {
            element.attr('href', '#');
        },
        loading: function( isLoading, view ) {
            if(isLoading) {// isLoading gives boolean value
                alert('loading');
            } else {
                alert('done');
            }
        }


    }); 
}

Then I setup the source: 然后设置源:

var source = '/wp-admin/admin-ajax.php?action=loop_events_output&venue=townsville';

Then I updated the source depending on user input: 然后我根据用户输入更新了源:

// execute when using filters
$('.calendar-controls input').change(function(){
    if (this.checked) {
        var checkedVal = $(this).val();

        var newSource = '/wp-admin/admin-ajax.php?action=loop_events_output&venue=' + checkedVal;
        $('#calendar').fullCalendar('removeEventSource', source)
        $('#calendar').fullCalendar('refetchEvents')
        $('#calendar').fullCalendar('addEventSource', newSource)
        $('#calendar').fullCalendar('refetchEvents');
        source = newSource;
    }
});

The most important part is removing the event source, and then adding the new event sources in. 最重要的部分是删除事件源,然后在其中添加新的事件源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM