我使用这个答案来过滤客户端的事件。
它适用于较新的事件,但我无法过滤从JSON加载的事件。
这是我的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');
});
});
和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>
我错过了什么?谢谢你的帮助。
我找到了答案。我使用了.change()来进行筛选。我还从.fullCalendar中删除了"event"one_answers"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);
}
})
}
});
});
});