如何在fullcalendar jquery中更新源事件?

如何在fullcalendar jquery中更新源事件?,jquery,fullcalendar,Jquery,Fullcalendar,在下拉列表中选择选项时的代码: actionChangeUsuario: function(data){ var self = this; var rut = ''; var subData = 0; $("#span_msj_id").hide(); $("#combo_usuarios_id").change(function() { $('#calendar').fullCalendar('refetchEvents');

在下拉列表中选择选项时的代码:

actionChangeUsuario: function(data){

    var self = this;
    var rut = '';
    var subData = 0;
    $("#span_msj_id").hide();

    $("#combo_usuarios_id").change(function() {
            $('#calendar').fullCalendar('refetchEvents');
            $.each(data, function(index,value){ 
                if(value.Id == $("#combo_usuarios_id").val()){
                    rut = value.rut;
                    nombre = value.nombre_trabajador+" "+value.apellido_trabajador;
                } 
            });
            $("#panel_calendar_id").show();
            if($("#combo_usuarios_id").val() == 0){
                $('#calendar').fullCalendar('removeEvents');
            }else{ 
                self.callTareasDatos(rut,nombre);
            }
    });

},
当我选择了一个选项并且一切正常时,我调用下一个函数:

代码:

如果一切正常,我调用下一个函数:

代码:

但是没有

我怎样才能解决这个问题,对不起,我的英语不好

编辑

我为每个事件添加了一个Id,这有帮助吗

那么:-

eventSource: null,

calendar: function(datos,rut,nombre){

    var self = this;
    console.info(datos);   

    $('#calendar').fullCalendar({
        height: 500,
        events: datos,
        editable: false,
            header: {
                left: '',
                center: 'prev title next',
                right: '',
            },
        eventRender: function (event, element) {
            var self = this;
            element.find('.fc-title').append(" (<strong>"+ event.estado +"</strong>)");
        },
        dayRender: function (date, cell) {
            var theDate = $(cell).data('date');
            var fcDaySkel = $("#calendar div.fc-content-skeleton td[data-date='"+theDate+"'].fc-day-number");
            fcDaySkel.prepend("<button type='button' style='margin-right:5px; padding:0; border: none; background: none;' id ='editar_"+theDate+"_control_id' class='btn btn-default addButton' title='Ver/Editar/Agregar'><i class='fa fa-eye'></i></button>");
            self.actionBtnCalendar(theDate,rut,nombre,datos); 


        },

    })

    if(self.eventSource != null)
       $('#calendar').fullCalendar('removeEventSource', self.eventSource);

    $('#calendar').fullCalendar('addEventSource', datos);         
    $('#calendar').fullCalendar('rerenderEvents'); 

    self.eventSource = datos;

}
eventSource:null,
日历:功能(datos、rut、nombre){
var self=这个;
控制台信息(datos);
$(“#日历”).fullCalendar({
身高:500,
活动:达托斯,
可编辑:false,
标题:{
左:'',
中间:“上一个标题下一个”,
对:'',
},
eventRender:函数(事件,元素){
var self=这个;
元素。查找('.fc title')。追加((“+event.estado+”);
},
dayRender:函数(日期、单元格){
var theDate=$(单元格).data('date');
var fcDaySkel=$(“#calendar div.fc-content-skeleton td[数据日期='”+日期+“'].fc日数”);
fcDaySkel.prepend(“”);
自我行动(日期、规则、名称、日期);
},
})
if(self.eventSource!=null)
$('#calendar').fullCalendar('removeEventSource',self.eventSource);
$(“#日历”).fullCalendar('addEventSource',datos);
$(“#日历”).fullCalendar('rerendervents');
self.eventSource=datos;
}

那么:-

eventSource: null,

calendar: function(datos,rut,nombre){

    var self = this;
    console.info(datos);   

    $('#calendar').fullCalendar({
        height: 500,
        events: datos,
        editable: false,
            header: {
                left: '',
                center: 'prev title next',
                right: '',
            },
        eventRender: function (event, element) {
            var self = this;
            element.find('.fc-title').append(" (<strong>"+ event.estado +"</strong>)");
        },
        dayRender: function (date, cell) {
            var theDate = $(cell).data('date');
            var fcDaySkel = $("#calendar div.fc-content-skeleton td[data-date='"+theDate+"'].fc-day-number");
            fcDaySkel.prepend("<button type='button' style='margin-right:5px; padding:0; border: none; background: none;' id ='editar_"+theDate+"_control_id' class='btn btn-default addButton' title='Ver/Editar/Agregar'><i class='fa fa-eye'></i></button>");
            self.actionBtnCalendar(theDate,rut,nombre,datos); 


        },

    })

    if(self.eventSource != null)
       $('#calendar').fullCalendar('removeEventSource', self.eventSource);

    $('#calendar').fullCalendar('addEventSource', datos);         
    $('#calendar').fullCalendar('rerenderEvents'); 

    self.eventSource = datos;

}
eventSource:null,
日历:功能(datos、rut、nombre){
var self=这个;
控制台信息(datos);
$(“#日历”).fullCalendar({
身高:500,
活动:达托斯,
可编辑:false,
标题:{
左:'',
中间:“上一个标题下一个”,
对:'',
},
eventRender:函数(事件,元素){
var self=这个;
元素。查找('.fc title')。追加((“+event.estado+”);
},
dayRender:函数(日期、单元格){
var theDate=$(单元格).data('date');
var fcDaySkel=$(“#calendar div.fc-content-skeleton td[数据日期='”+日期+“'].fc日数”);
fcDaySkel.prepend(“”);
自我行动(日期、规则、名称、日期);
},
})
if(self.eventSource!=null)
$('#calendar').fullCalendar('removeEventSource',self.eventSource);
$(“#日历”).fullCalendar('addEventSource',datos);
$(“#日历”).fullCalendar('rerendervents');
self.eventSource=datos;
}

您是否尝试将
'id'
字段添加到表示事件的对象中?这对我很管用

编辑:您的函数应如下所示:

calendar: function(datos,rut,nombre){

    var self = this;
    console.info(datos);   

    /*$('#calendar').fullCalendar({
        height: 500,
        events: datos,
        editable: false,
            header: {
                left: '',
                center: 'prev title next',
                right: '',
            },
        eventRender: function (event, element) {
            var self = this;
            element.find('.fc-title').append(" (<strong>"+ event.estado +"</strong>)");
        },
        dayRender: function (date, cell) {
            var theDate = $(cell).data('date');
            var fcDaySkel = $("#calendar div.fc-content-skeleton td[data-date='"+theDate+"'].fc-day-number");
            fcDaySkel.prepend("<button type='button' style='margin-right:5px; padding:0; border: none; background: none;' id ='editar_"+theDate+"_control_id' class='btn btn-default addButton' title='Ver/Editar/Agregar'><i class='fa fa-eye'></i></button>");
            self.actionBtnCalendar(theDate,rut,nombre,datos); 
        },

    })*/

    // Try either the option 1 or the option 2
    // 1 RemoveEvents as a whole
    $('#calendar').fullCalendar('removeEvents');
    // 2 For me 'removeEvents' did not work, so I had to remove all the events one by one
    $('#calendar').fullCalendar('removeEvents', hereTheEventIdThatYouWantToRemoveAsString);


    $('#calendar').fullCalendar('addEventSource', datos);   

    // Not sure if this step is necessary      
    $('#calendar').fullCalendar('rerenderEvents'); 
}
日历:功能(datos、rut、nombre){
var self=这个;
控制台信息(datos);
/*$(“#日历”).fullCalendar({
身高:500,
活动:达托斯,
可编辑:false,
标题:{
左:'',
中间:“上一个标题下一个”,
对:'',
},
eventRender:函数(事件,元素){
var self=这个;
元素。查找('.fc title')。追加((“+event.estado+”);
},
dayRender:函数(日期、单元格){
var theDate=$(单元格).data('date');
var fcDaySkel=$(“#calendar div.fc-content-skeleton td[数据日期='”+日期+“'].fc日数”);
fcDaySkel.prepend(“”);
自我行动(日期、规则、名称、日期);
},
})*/
//请尝试选项1或选项2
//1将通风口作为一个整体移除
$(“#calendar”).fullCalendar('removeEvents');
//2对于我来说,“removeEvents”不起作用,因此我必须逐个删除所有事件
$(“#calendar”).fullCalendar(“removeEvents”,此处是您要移除字符串的通知);
$(“#日历”).fullCalendar('addEventSource',datos);
//不确定是否需要此步骤
$(“#日历”).fullCalendar('rerendervents');
}

请注意注释的代码段。它会被注释,因为您在那里做的是重新加载日历,这应该是正确的,但由于某些原因,它没有执行其工作,并且似乎什么也不做。然后,您应该能够根据需要添加/删除事件。如果这个解决方案不起作用,我想我再也帮不了你了:(

你有没有尝试向表示事件的对象添加
'id'
字段?这对我来说很有效

编辑:您的函数应如下所示:

calendar: function(datos,rut,nombre){

    var self = this;
    console.info(datos);   

    /*$('#calendar').fullCalendar({
        height: 500,
        events: datos,
        editable: false,
            header: {
                left: '',
                center: 'prev title next',
                right: '',
            },
        eventRender: function (event, element) {
            var self = this;
            element.find('.fc-title').append(" (<strong>"+ event.estado +"</strong>)");
        },
        dayRender: function (date, cell) {
            var theDate = $(cell).data('date');
            var fcDaySkel = $("#calendar div.fc-content-skeleton td[data-date='"+theDate+"'].fc-day-number");
            fcDaySkel.prepend("<button type='button' style='margin-right:5px; padding:0; border: none; background: none;' id ='editar_"+theDate+"_control_id' class='btn btn-default addButton' title='Ver/Editar/Agregar'><i class='fa fa-eye'></i></button>");
            self.actionBtnCalendar(theDate,rut,nombre,datos); 
        },

    })*/

    // Try either the option 1 or the option 2
    // 1 RemoveEvents as a whole
    $('#calendar').fullCalendar('removeEvents');
    // 2 For me 'removeEvents' did not work, so I had to remove all the events one by one
    $('#calendar').fullCalendar('removeEvents', hereTheEventIdThatYouWantToRemoveAsString);


    $('#calendar').fullCalendar('addEventSource', datos);   

    // Not sure if this step is necessary      
    $('#calendar').fullCalendar('rerenderEvents'); 
}
日历:功能(datos、rut、nombre){
var self=这个;
控制台信息(datos);
/*$(“#日历”).fullCalendar({
身高:500,
活动:达托斯,
可编辑:false,
标题:{
左:'',
中间:“上一个标题下一个”,
对:'',
},
eventRender:函数(事件,元素){
var self=这个;
元素。查找('.fc title')。追加((“+event.estado+”);
},
dayRender:函数(日期、单元格){
var theDate=$(单元格).data('date');
var fcDaySkel=$(“#calendar div.fc-content-skeleton td[数据日期='”+日期+“'].fc日数”);
fcDaySkel.prepend(“”);
自我行动(日期、规则、名称、日期);
},
})*/
//请尝试选项1或选项2
//1将通风口作为一个整体移除
$(“#calendar”).fullCalendar('removeEvents');
//2对于我来说,“removeEvents”不起作用,因此我必须逐个删除所有事件
$(“#calendar”).fullCalendar(“removeEvents”,此处是您要移除字符串的通知);
$(“#日历”).fullCalendar('addEventSource',datos);
//不确定是否需要此步骤
$(“#日历”).fullCalendar('rerendervents');
}
请注意已注释的饼图
calendar: function(datos,rut,nombre){

    var self = this;
    console.info(datos);   

    /*$('#calendar').fullCalendar({
        height: 500,
        events: datos,
        editable: false,
            header: {
                left: '',
                center: 'prev title next',
                right: '',
            },
        eventRender: function (event, element) {
            var self = this;
            element.find('.fc-title').append(" (<strong>"+ event.estado +"</strong>)");
        },
        dayRender: function (date, cell) {
            var theDate = $(cell).data('date');
            var fcDaySkel = $("#calendar div.fc-content-skeleton td[data-date='"+theDate+"'].fc-day-number");
            fcDaySkel.prepend("<button type='button' style='margin-right:5px; padding:0; border: none; background: none;' id ='editar_"+theDate+"_control_id' class='btn btn-default addButton' title='Ver/Editar/Agregar'><i class='fa fa-eye'></i></button>");
            self.actionBtnCalendar(theDate,rut,nombre,datos); 
        },

    })*/

    // Try either the option 1 or the option 2
    // 1 RemoveEvents as a whole
    $('#calendar').fullCalendar('removeEvents');
    // 2 For me 'removeEvents' did not work, so I had to remove all the events one by one
    $('#calendar').fullCalendar('removeEvents', hereTheEventIdThatYouWantToRemoveAsString);


    $('#calendar').fullCalendar('addEventSource', datos);   

    // Not sure if this step is necessary      
    $('#calendar').fullCalendar('rerenderEvents'); 
}