簡體   English   中英

使用全日歷的重復事件和非重復事件

[英]recurring event and non-recurring event using 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; ?>',
               }]
      },
]

下圖顯示了我日歷的當前狀態: 日歷

從上圖可以看出,有氧運動一直在不斷進行。 除了使用事件呈現功能之外,是否有一種方法可以根據范圍內的結束日期來停止重復發生的事件?

注意: <?php echo $start; ?> <?php echo $start; ?><?php echo $end; ?> <?php echo $end; ?>是格式為YYYY-MM-DD的日期。

嘗試ADyson解決方案后已更新: 更新日歷

   <?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; ?>

數據

顯然,由於它們位於foreach循環中,因此進入了周期性和非周期性事件對象。

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; ?>

您想要的完全有可能。 正如我在評論中提到的,您要做的就是修改eventRender函數,以檢查正在渲染的事件是否存在“ ranges”屬性。 如果是這樣,則應用范圍定義的重復規則。 如果不是,則只允許它正常渲染而不會產生干擾:

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
  }
}

為此,您的事件可以具有以下結構:

非重復示例:

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

重復的示例:

{
  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"
    }]
}

在此處查看有效的演示,其中包含重復事件和非重復事件: http : //jsfiddle.net/sbxpv25p/27/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM