Fullcalendar:同一天的多个事件集中在一个事件中
我有一个带有周视图的全日历。
我已修改 fullcalendar 以显示带有事件的数字:
function slotSegHtml(event, seg) {
[...]
html +=
" class='" + classes.join(' ') + "'" +
" style='position:absolute;z-index:8;top:" + seg.top + "px;left:" + seg.left + "px;" + skinCss + "'" +
">" +
"<span class='fc-event-inner fc-event-qty'>"+htmlEscape(event.qty)+"</span>"+
[...]
return html;
}
在 drop 函数中:
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.id = idevento++;
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
copiedEventObject.className = 'newEvent';
copiedEventObject.qty = '1';
//buscar eventos
var listevents = $('#calendar').fullCalendar('clientEvents',function(event) {
if(date.getFullYear()!=event.start.getFullYear())return false;
if(date.getMonth()!=event.start.getMonth())return false;
if(date.getDay()!=event.start.getDay())return false;
if(date.getHours()!=event.start.getHours())return false;
//aparte tienen que ser del mismo tipo
if(event.title!=copiedEventObject.title)return false;
return true;
});
if(typeof listevents === 'object'){
//augmentar la cantidad
eventoantiguo = listevents[0];
copiedEventObject.qty = parseInt(eventoantiguo.qty)+1;
//borrar el objeto antiguo
$("#calendar").fullCalendar('removeEvents', eventoantiguo.id);
}
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
但是当我在同一天和同一小时内删除第二个事件时,所有事件都会消失。
对不起我的英语。
我认为归咎于: $('#calendar').fullCalendar('renderEvent', CopyEventObject, true);
萤火虫 说: 没有方法“替换”
未捕获的类型错误:对象 2在此函数中
function htmlEscape(s) {
return s.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/\n/g, '<br />');
}
(fullcalendar.js)
I have a Fullcalendar with the week view.
I have modified fullcalendar to show a number with the event:
function slotSegHtml(event, seg) {
[...]
html +=
" class='" + classes.join(' ') + "'" +
" style='position:absolute;z-index:8;top:" + seg.top + "px;left:" + seg.left + "px;" + skinCss + "'" +
">" +
"<span class='fc-event-inner fc-event-qty'>"+htmlEscape(event.qty)+"</span>"+
[...]
return html;
}
in the drop function:
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = $(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.id = idevento++;
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
copiedEventObject.className = 'newEvent';
copiedEventObject.qty = '1';
//buscar eventos
var listevents = $('#calendar').fullCalendar('clientEvents',function(event) {
if(date.getFullYear()!=event.start.getFullYear())return false;
if(date.getMonth()!=event.start.getMonth())return false;
if(date.getDay()!=event.start.getDay())return false;
if(date.getHours()!=event.start.getHours())return false;
//aparte tienen que ser del mismo tipo
if(event.title!=copiedEventObject.title)return false;
return true;
});
if(typeof listevents === 'object'){
//augmentar la cantidad
eventoantiguo = listevents[0];
copiedEventObject.qty = parseInt(eventoantiguo.qty)+1;
//borrar el objeto antiguo
$("#calendar").fullCalendar('removeEvents', eventoantiguo.id);
}
// render the event on the calendar
// the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
but when I drop the second event in the same day and hour, all events disapear.
sorry for my english.
I think the blame line is:
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
firebug says:
Uncaught TypeError: Object 2 has no method 'replace'
in this function
function htmlEscape(s) {
return s.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/\n/g, '<br />');
}
(fullcalendar.js)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用全日历的Eventlimit,
假设您想对单日的所有事件进行分组,那么只需将事件限制设置为 1,如下所示:
Use Eventlimit of Full Calendar ,
Suppose You want to Group all Events of Single day then Just set limit of event to 1 as follows:
我用这一行解决了问题:
因为 function "function htmlEscape(s) {" "s" 必须是字符串
谢谢!
I solved the problem with this line:
because function "function htmlEscape(s) {" "s" must be an string
Thank you!