【问题标题】:FullCalendar display events on dayClickFullCalendar 在 dayClick 上显示事件
【发布时间】:2015-04-14 21:09:09
【问题描述】:

fullCalendar 中的dayClick 定义为:

dayClick: function (start, allDay, jsEvent, view) {
    alert('You clicked me!');
}

当用户点击一天时触发。

我想在用户点击某一天时访问事件数据。将 eventClick 函数合并到 dayClick 中,这样当我单击特定日期时,我会获得该特定日期发生的所有事件的事件标题、开始时间和结束时间。

【问题讨论】:

  • 如果当天没有任何事件怎么办?
  • @RahilWazir:在这种情况下,我想它会给出null。我的意思是,假设我们将事件存储在一个数组中,那么该数组将为空。
  • 那你为什么不用eventClick
  • @RahilWazir:我试过了。但无法弄清楚如何将 eventClick 与 dayClick 结合起来。我对javascript很陌生。我想要点击特定日期时当天的所有事件数据。
  • @xan 那天有活动吗?

标签: php fullcalendar


【解决方案1】:

希望对你有帮助

$('#calendar').fullCalendar({
        dayClick: function(date, allDay, jsEvent, view) {
                var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 0, 0, 0).getTime();
                var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 23, 59, 59).getTime();
                var cache = new Date().getTime();
                $.getJSON("/json-events.php?start="+startDate+"&end="+endDate+"&_="+cache,
                    function(data) {
                        // do stuff with the JSOn data
                    }
        }
    });

【讨论】:

  • 我不知道这会有什么帮助。我已经有一个包含某些事件的日历。我只想在单击某一天时显示事件的标题(当天发生的所有事件的标题)。此外,您的代码不起作用。
  • 为什么不呢?我认为这里问的是同样的问题:stackoverflow.com/questions/2516050/…
【解决方案2】:

你可以试试这个:

eventClick: function(xEvent, jsEvent, view) {
    alert("Title: " + xEvent.title             //Get the event title
          + "\n StartTime: " + xEvent.start    //Get the event start date
          + "\n EndTime: " + xEvent.end        //Get the event end date
    );

    console.log(xEvent); //See your console for all event properties/objects
}

xEvent 属性/对象列表。

【讨论】:

  • 当用户点击“事件”时触发。我想要用户点击“day”时的事件数据。
  • @con_28 如果一天没有事件,那么当然没有事件数据是没有意义的。只有当日有活动注册时,才能获取活动数据。
  • 就我而言,除了星期日之外,所有日子至少有一个事件。
  • 那么上面的 sn-p 对你有用,除了星期天!
  • 如果我点击一个事件,上面的代码就可以工作。我根本不想要那个。我想要一种机制来在点击一天时显示特定一天的事件。如果当天没有任何事件,它将简单地输出一个空对象。
【解决方案3】:
dayClick: function(date, allDay, jsEvent, view) {
    var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 0, 0, 0).getTime();
    var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 23, 59, 59).getTime();
    var cache = new Date().getTime();
    $.getJSON("/json-events.php?start="+startDate+"&end="+endDate+"&_="+cache,
        function(data) {
            // do stuff with the JSOn data
    });
    alert('ENTROU!');
},

现在可以了

它会打开一个警报,您只需输入想要的信息。

【讨论】:

    【解决方案4】:

    我想这就是你要找的。​​p>

    dayClick: function(date, allDay, jsEvent, view) {
      var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate()+1);
      //This gives the next day of the clicked day('date' contains the clicked day)
    
      var todaysEvents = $('#calendar').fullCalendar('clientEvents', function(event) {
        // Below statement returns the EVENT OBJECT of the clicked day after comparing the two dates
        return event.start >= date && event.start < date2;
      });
      // You can now access the returned object & extract what you want
      // console.log(todaysEvents); --> returns the complete object
      // console.log(todaysEvents[0].title); --> returns that day's event title
    },
    

    我希望这会有所帮助。

    【讨论】:

    • 您首先必须使用 toDate 函数将日期从时刻 js 转换为 javascript 日期。所以jsDate = date.toDate(),用jsDate代替date
    • date.getDate()+1 不起作用...这可能是 32。无效日期。
    猜你喜欢
    • 2014-02-04
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    相关资源
    最近更新 更多