Fullcalendar clientEvents长度为零 [英] Fullcalendar clientEvents has zero length

查看:99
本文介绍了Fullcalendar clientEvents长度为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于来自URL的信息加载页面和日历后,尝试让我的突出显示特定事件时,我了解到我已获取事件对象以使用 updateEvent 。我还了解到,使用 clientEvents 是您应该这样做的方式。当我尝试使用 clientEvents 时,我只是返回一个空数组。文档和似乎同意,如果我不' t提供了一个可选的参数,那么我应该返回一个当前在我的日历上的所有数组。

While trying to get my highlight a particular event after the page and calendar was loaded based on information from the URL I learned that I had get the event object to use updateEvent. I also learned that that using clientEvents is the way you are supposed to do this. As I try to use clientEvents I am simply getting an empty array back. The documentation and source seem to agree, that if I don't provide an optional paramater, then I should get back an array of everything currently on my calendar.

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {

  $('#calendar').fullCalendar({
    defaultView: 'agendaWeek',
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay',
    },
  });

  $('#calendar').fullCalendar('addEventSource',
    { url: 'https://www.example.org/combinedcalendar/feed/json.php',
      dataType: 'jsonp'});

  console.log($('#calendar').fullCalendar('clientEvents').length);

});
</script>
<div id='calendar'></div>

在javascript控制台中记录的值是 0 ;

The value logged in the javascript console is 0;

推荐答案

当我编写这个问题并测试时,我意识到本来应该是显而易见的。使用ajax的 $('#calendar')。fullCalendar('addEventSource',...); 调用是异步的。因此,在事件数据实际下载并添加到日历中之前, clientEvents 记录到控制台发生了事件。

As I was composing this question and testing things out I realized what should have been obvious in the first place. The $('#calendar').fullCalendar('addEventSource',...); call which is using ajax is asynchronous. So the logging of clientEvents to the console happend before the event data was actually downloaded and added to the calendar.

我将日志记录移至fullCalendar 加载函数中,触发器当加载开始或完成时。

I moved my logging into the fullCalendar loading function which triggers when a loading is started or completes.

$('#calendar').fullCalendar({ 
  loading:function(isLoading,view){
    if (!isLoading)
    {
      console.log($('#calendar').fullCalendar('clientEvents').length);
    }
  },
  ...
});

这篇关于Fullcalendar clientEvents长度为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆