简体   繁体   English

在客户端过滤 FullCalendar 事件

[英]Filtering FullCalendar events on client side


I'm using this answer to filter the events on client side.我正在使用此答案来过滤客户端的事件。

It works very well for newer events, but I can't filter events loaded from the JSON.它适用于较新的事件,但我无法过滤从 JSON 加载的事件。

Here is my JS code:这是我的 JS 代码:

$(document).ready(function() {
    var idEspacoFisico=$('#seleciona option:selected').val();
    $("#calendar").fullCalendar({
        events: 'eventos/getEventos.json',//can't filter these
        eventRender: function eventRender( event, element, view ) {
            //from the answer.
            return ['0',event.espacoFisico].indexOf($('#seleciona option:selected').val()) >= 0
        },
        select: function(start, end){
            //When created here, I can use the the eventRender to filter.
        }
    });
    $('#seleciona').change(function(){
        $("#calendar").fullCalendar('rerenderEvents');
    });
});

And HTML:和 HTML:

<select class="form-control" id="seleciona">
    <option value="0">Selecione</option>
    <option value="1">LAB 1</option>
    <option value="2">LAB 2</option>
    ...
</select>

<div id="calendar"></div>

I miss something?我想念什么? Thanks for the help.谢谢您的帮助。

I found an answer.我找到了答案。 I used the .change() to do the filter.我使用 .change() 来做过滤。 I also removed the 'event' and 'eventRender' from the .fullCalendar to avoid conflict.我还从 .fullCalendar 中删除了 'event' 和 'eventRender' 以避免冲突。

$(document).ready(function() {
var idEspacoFisico=$('#seleciona option:selected').val();
$("#calendar").fullCalendar({
    select: function(start, end){
    ...
    }
});
$('#seleciona').change(function(){
    $("#calendar").fullCalendar('removeEvents');//remove the old filtered events
    var idEspacoFisico=$('#seleciona option:selected').val();//filter based on the select value
    $.ajax({
        type:"POST",
        url:'eventos/getEventos.json', //get events
        success: function(data){
            $.each(data,function(index,value){//for each event, I will compare the value with the filter, if true, render it.
                if(value.espacoFisico==idEspacoFisico){
                    $("#calendar").fullCalendar('renderEvent', value, true);
                }
            })
        }
    });
});
});

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

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