在FullCalendar dayClick事件中,我可以获取点击日期中已存在的事件吗? [英] In the FullCalendar dayClick event, can I get the events that already exist in clicked date?

查看:2660
本文介绍了在FullCalendar dayClick事件中,我可以获取点击日期中已存在的事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FullCalendar dayClick事件中,我可以获取点击日期中已存在的事件吗?

http://arshaw.com/fullcalendar/docs/mouse/dayClick/



让我解释一下我的项目
我写了一个简单的php站点,允许用户在日历上添加/编辑事件。


  • 只有单个活动可以添加到日期。

  • 如果用户点击空日期,则会显示新的事件弹出窗口(我使用dayclick事件)。事件弹出窗口将显示(我使用eventclick事件)。



问题是当用户点击事件区域外(上区域或下区域)的日期与现有的事件,它会提高dayclick而不是eventclick。
如果日期中存在事件,我如何触发eventclick事件并跳过dayclick事件?

解决方案

存储在客户端或服务器端的事件?如果在客户端,这应该特别适用于如果您想要点击时间的事件:

  $('#calendar' ).fullCalendar({
dayClick:function(date,allDay,jsEvent,view){
$('#calendar')。fullCalendar('clientEvents',function(event){
if (event.start< = date&& event.end> = date){
return true;
}
return false;
});
}
});

这会使点击时间重叠的事件存储在客户端。如果您想要在该日期发生的所有事件,无论是全天候插槽还是时间插槽点击。

  $('#calendar')。fullCalendar({
dayClick:function(date,allDay ,jsEvent,view){
if(!allDay){
// strip time information
date = new Date(date.getFullYear(),date.getMonth(),date.getDay ));
}
$('#calendar')。fullCalendar('clientEvents',function(event){
if(event.start< = date&&&event; end> = date){
return true;
}
return false;
});
}
});

如果您的事件存储在服务器上,则需要在dayClick中提供日期回调并使用它来构建一个调用你的服务器以获得你需要的任何格式的信息。
$ b

编辑如果做一次往返或尝试以其他方式获取信息

  $('#calendar')。fullCalendar({
dayClick:function日期,allDay,jsEvent,查看){
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){
//处理JSOn数据
}
}
});

如果您不想往返,也可以查看fullCalendar.js中的refetchEvents中发生的情况。如果你不介意与fullCalendar树干分歧,你可以在某处保存获取的事件,这样你就不会执行一堆DOM操作(取决于事件的数量,因为它们会变大而变得笨拙)。


In the FullCalendar dayClick event, can I get the events that already exist in clicked date?

http://arshaw.com/fullcalendar/docs/mouse/dayClick/

Let me explain a little about my project I'm writing a simple php site that allow user to add/edit event on calendar.

  • Only single event can add to a date.
  • If user click on empty date, New event popup will show (I use dayclick event).
  • If user click date with existing event, Edit event popup will show (I use eventclick event).

The problem is when user click outside of event area (upper area or bottom area) of a date with existing event, it raise dayclick instead of eventclick. How can I trigger eventclick event and skip dayclick event if there is existing event in the date?

解决方案

Are your events stored on the client side or on the server side? If on the client side, this should work specifically if you want the event in that clicked time:

$('#calendar').fullCalendar({
    dayClick: function(date, allDay, jsEvent, view) {
            $('#calendar').fullCalendar('clientEvents', function(event) {
                if(event.start <= date && event.end >= date) {
                    return true;
                }
                return false;
            });
    }
});

This will give events that overlap the clicked time and are stored on the client side. For the all-day slot, it will give all events overlapping that day.

If you want all events on that date itself, regardless of whether the allDay slot or a time slot was clicked.

$('#calendar').fullCalendar({
    dayClick: function(date, allDay, jsEvent, view) {
            if(!allDay) {
                // strip time information
                date = new Date(date.getFullYear(), date.getMonth(), date.getDay());
            }
            $('#calendar').fullCalendar('clientEvents', function(event) {
                if(event.start <= date && event.end >= date) {
                    return true;
                }
                return false;
            });
    }
});

If your events are stored on the server, you'll want to take the date provided in your dayClick callback and use it to construct a call to your server to get the info in whatever format you need.

EDIT If doing a round trip or trying to get the information other ways

$('#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
                }
    }
});

And if you don't want the round trip, you can also take a look at what happens in, say, refetchEvents in fullCalendar.js. If you don't mind diverging from the fullCalendar trunk, you can save off fetched events somewhere so that you aren't doing a bunch of DOM manipulation (depending on the number of events, as they get large that will get unwieldy).

这篇关于在FullCalendar dayClick事件中,我可以获取点击日期中已存在的事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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