【问题标题】:FullCalendar: Add an event by the day of the weekFullCalendar:按星期几添加事件
【发布时间】:2017-01-12 07:32:28
【问题描述】:

我正在建造一所小学,我有很多学科,它是day of the week。我需要将这些学科插入日历。问题是:
无法仅通过day of the week 添加。见:

今天是星期日(2016 年 4 月 9 日)。但日历天数来自过去一周。

所以,如果你有:

var day = 'monday';  

当你要去insert an event in runtime 你会这样做:

$('#calendario').fullCalendar(
  'renderEvent',
  {                     
    id: id 
    title:  $(this).find('a').text(),   
    start: year+ '-' +month+ '-' +day+ 'T' + startTime,
    end:   year+ '-' +month+ '-' +day+ 'T' + endTime,
    backgroundColor: color,
    className: someClass
  }
)

如您所见,我必须指定当月的day

问题是:即使使用weekView,我也无法仅使用工作日来处理事件...我必须提供整个日期(YYYY-MM-DD)。
今天是星期日(04/09/2016)。日历是上个月的一半,当月的一半。我应该如何仅通过 day of the week 插入事件?

还尝试使用momentjs

moment().day(1).hours(10).minutes(0).format('YYYY-MM-DD')  

moment 将返回一周的第二天(0 - 星期日,1 - 星期一),即 05(当前周),与 fullCalendar 29(上周)不同。所以我不知道如何将我的学科/事件插入日历。

【问题讨论】:

    标签: javascript fullcalendar


    【解决方案1】:

    您可以将事件作为函数提供并循环显示当前显示的时间段,在特定日期创建事件

    https://jsfiddle.net/0roafa2f/

    $('#calendar').fullCalendar({
        events: dowEvents
    });
    
    function dowEvents(start, end, tz, callback) {
      var events = [];
      var curr = start;
      while(curr <= end) {
        if(curr.format('dddd') === 'Monday') {
            events.push({
            title: 'Monday event',
            start: moment(curr)
          });
        }
        curr = curr.add(1, 'day');
      }
      callback(events);
    }
    

    【讨论】:

      【解决方案2】:

      根据本页demo的源码: https://fullcalendar.io/ 同时,events 是一个数组对象,可以手动列出,从带有 json 响应的 url 获取或从此处所述的函数获取:https://fullcalendar.io/docs/event-data

      $(function() {
      
        var todayDate = moment().startOf('day');
        var YM = todayDate.format('YYYY-MM');
        var YESTERDAY = todayDate.clone().subtract(1, 'day').format('YYYY-MM-DD');
        var TODAY = todayDate.format('YYYY-MM-DD');
        var TOMORROW = todayDate.clone().add(1, 'day').format('YYYY-MM-DD');
      
        $('#calendar').fullCalendar({
          header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay,listWeek'
          },
          editable: true,
          eventLimit: true, // allow "more" link when too many events
          navLinks: true,
          events: [
            {
              title: 'All Day Event',
              start: YM + '-01'
            },
            {
              title: 'Long Event',
              start: YM + '-07',
              end: YM + '-10'
            },
            {
              id: 999,
              title: 'Repeating Event',
              start: YM + '-09T16:00:00'
            },
            {
              id: 999,
              title: 'Repeating Event',
              start: YM + '-16T16:00:00'
            },
            {
              title: 'Conference',
              start: YESTERDAY,
              end: TOMORROW
            },
            {
              title: 'Meeting',
              start: TODAY + 'T10:30:00',
              end: TODAY + 'T12:30:00'
            },
            {
              title: 'Lunch',
              start: TODAY + 'T12:00:00'
            },
            {
              title: 'Meeting',
              start: TODAY + 'T14:30:00'
            },
            {
              title: 'Happy Hour',
              start: TODAY + 'T17:30:00'
            },
            {
              title: 'Dinner',
              start: TODAY + 'T20:00:00'
            },
            {
              title: 'Birthday Party',
              start: TOMORROW + 'T07:00:00'
            },
            {
              title: 'Click for Google',
              url: 'http://google.com/',
              start: YM + '-28'
            }
          ]
        });
      });
      

      【讨论】:

        【解决方案3】:

        据我了解,如果您希望事件基于(太阳、星期一、星期二)等日期,您可以使用 dow 它接受数组 [0,1,2,3,4 ,5,6] sun,mon,tues 分别。如果您希望它每天重复,请使用 start:"00:00:00"。例如 试试这个

         events.push({
            start: '00:00:00',
            title: 'recursive event', 
            dow: [0,1,2] // each sun,mon,tues
              })
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-05-13
          • 2022-08-10
          • 1970-01-01
          • 1970-01-01
          • 2013-06-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多