douci1677 2017-10-03 20:12
浏览 285
已采纳

使用fullcalendar重复发生的事件和非重复事件

events: [

     {
      id: '<?php echo $event['id']; ?>',
      title: '<?php echo $event['title']; ?>',
      color: '<?php echo $event['color']; ?>',
      start: '<?php echo $start; ?>',
      end: '<?php echo $end; ?>',
      dow: '<?php echo $dow; ?>',
      ranges: [{
                 start: '<?php echo $start; ?>', 
                 end: '<?php echo $end; ?>',
               }]
      },
]

Following image below shows my current status of my calendar: Calendar

As seen from the image above, the cardio training has been recurring non-stop. Is there a way to stop the recurring event based on the end date in ranges, other than using event render function?

Take note: <?php echo $start; ?> and <?php echo $end; ?> is a date formatted in YYYY-MM-DD.

UPDATED after attempting ADyson's solution: updatedCalendar

   <?php foreach ($events as $event): ..... ?> 
{
      id: '<?php echo $event['id']; ?>',
      title: '<?php echo $event['title']; ?>',
      color: '<?php echo $event['color']; ?>',
      start: '04:00',
      end: '05:00',
      dow: '<?php echo $dow; ?>',
      ranges: [{
                 start: '<?php echo $start; ?>', 
                 end: '<?php echo $end; ?>',
               }]
}, 
{
      id: '<?php echo $event['id']; ?>',
      title: '<?php echo $event['title']; ?>',
      color: '<?php echo $event['color']; ?>',
      start: '<?php echo $start; ?>',
      end: '<?php echo $end; ?>',
} <?php endforeach; ?>

data

Apparently, it went into recurring and non-recurring event objects due to they are in the foreach loop.

SOLUTION

events:[
    <?php 
    inside the foreach loop:
    ..........
     if ($dow == "") {
        ?>
        {
          id: '<?php echo $event['id']; ?>',
          title: '<?php echo $event['title']; ?>',
          color: '<?php echo $event['color']; ?>',
          start: '<?php echo $start; ?>',
          end: '<?php echo $end; ?>',
        },
 <?php }
       else {?>
        {
          id: '<?php echo $event['id']; ?>',
          title: '<?php echo $event['title']; ?>',
          color: '<?php echo $event['color']; ?>',
          start: '04:00',
          end: '05:00',
          dow: '<?php echo $dow; ?>',
          ranges: [{
                     start: '<?php echo $start; ?>', 
                     end: '<?php echo $end; ?>',
                   }]
       },
   <?php } ?>
<?php endforeach; ?>
  • 写回答

1条回答

  • dsw8292301 2017-10-04 10:19
    关注

    What you want is perfectly possible. As I mentioned in the comments, all you have to do is modify the eventRender function to check whether the "ranges" property exists on the event being rendered. If it does, then apply the recurrence rules defined by the ranges. If not, then just allow it to render normally with no interference:

    eventRender: function(event) {
      //only apply recurrence rules if the event has a "ranges" property
      if (event.ranges) {
        return (event.ranges.filter(function(range) { // test event against all the ranges
    
          return (event.start.isBefore(range.end) &&
            event.end.isAfter(range.start));
    
        }).length) > 0; //if it isn't in one of the ranges, don't render it (by returning false)
      } else {
        return true; //just allow the event to render normally if it's not recurring
      }
    }
    

    For this to work, your events can have the following structures:

    Non-recurring example:

    {
      title: 'Non Recurring Event',
      start: "2017-10-03T10:30:00",
      end: "2017-10-03T11:30:00",
      allDay: false
    }
    

    Recurring example:

    {
      id: 1,
      title: "Recurring Event",
      start: "10:00",
      end: "12:00",
      dow: [1,3,4],
      ranges: [{
          start: "2017-10-01T09:30:00",
          end: "2017-10-04T15:30:00"
        }, {
          start: 2017-10-05T10:00:00",
          end: 2017-10-15T13:30:00"
        }]
    }
    

    See a working demo here, containing both recurring and non-recurring events: http://jsfiddle.net/sbxpv25p/27/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题