Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery removeEvents仅删除当月的事件_Jquery_Fullcalendar - Fatal编程技术网

Jquery removeEvents仅删除当月的事件

Jquery removeEvents仅删除当月的事件,jquery,fullcalendar,Jquery,Fullcalendar,当我使用$('#calendar).fullCalendar('removeEvents'),这仅从当月(12月)删除事件,而不从其他月份(11月、1月、2月…)删除事件 如何删除所有事件 $(document).ready(function(){ var UsrAux; UsrAux=$('#name').val(); $('#name').blur(function(){ UsrAux=$('

当我使用
$('#calendar).fullCalendar('removeEvents'),这仅从当月(12月)删除事件,而不从其他月份(11月、1月、2月…)删除事件

如何删除所有事件

$(document).ready(function(){
    var UsrAux;        
    UsrAux=$('#name').val();                  
    $('#name').blur(function(){    
        UsrAux=$('#name').val();                        
        var source =   {
            url: 'CalendarServer.php',
            type: 'POST',
            data: {                            // Parms
                uno: 'Somenthing',    
                UsrCdg: UsrAux                                            
            },
            error: function() {
                alert('error!');
            },
            color: '#e2ebef',   // a non-ajax option
            textColor: 'black' // a non-ajax option
        };                                 
        $('#calendar').fullCalendar('removeEvents');
        $('#calendar').fullCalendar('addEventSource', source);
    });  

    $('#calendar').fullCalendar({
        draggable: true, 
        height: 400,    
        cache: true, 
        eventSources: [
        // your event source
        {
            url: 'CalendarServer.php',
            type: 'POST',
            data: {                            // Parms
                uno: 'something',    
                UsrCdg: $('#name').val()                                            
            },
            error: function() {
                alert('error!');
            },
            color: '#e2ebef',   // a non-ajax option
            textColor: 'black' // a non-ajax option
        }]       
    });
});

如果要删除事件的子集,在本例中,我们将通过添加到每个事件的附加类名(“模板”)进行筛选:

$myCal.fullCalendar( 'removeEvents', function( event ) {
     if( _.indexOf( event.className, 'template' ) > -1 ) {
          return true;
     }
     else {
          return false;
     }
} );
在您的情况下,我认为每个月的更改都是从给定的源重新加载的。我避免这种行为的一种方法是在日历之外加载源,然后只注入数组。例如:

var myCalEvents = fetchEvents(...);

// this is not reload with each change in calendar view 
$myCal.fullCalendar( 'addEventSource', myCalEvents );
编辑

我会把这个问题分解

首先创建一个函数来下拉每个人的日历

function getCalByPersonId( perId ) {
  // returns an array of fullcalender events pulled from the server
  // note each event will have a css class added by the name of
  // 'perid_x' where 'x' ist he perId parameter
  return ...{ajax call goes here}
}
接下来,创建一个函数来处理人员更改事件

function handlePersonChangeEvent( event ) {
  // first extract person id
  var perId = ... {code to get the person id}

  // clear any existing events for a previously selected person
  if( currentPerId && currentPerId !== perId ) {
    ...{remove code from above goes here, but replace 'template' with 'perId_x' where x is the currentPerId}
  }

  // add the new person's events to the calendar
  $myCal.fullCalendar( 'addEventSource', function() {
    return getCalByPersonId( perId );
  } );

  // set the current person id
  currentPerId = perId;
}

我相信这或多或少会实现你想要实现的目标。

你想要做什么?Remove events(删除事件)只会删除可见的事件,每次移动到新月份时,它都会再次获取该月份的事件并显示它们。您将事件存储在哪里?最好是从数据库或其他任何地方删除它们,而不是不显示它们。嗨,我有一个输入(#名称)。它包含员工价值。例如,我有两名员工(A和B)。员工A在12月有事件。员工B在1月有事件。所以1。输入值包含员工A,月份是12月。所有都可以。2.输入值为员工B,月份为12月,一切正常。3.如果我更改月份(明年1月),我会获取一些员工A事件。但我需要日历只显示员工B事件。谢谢