将数据传递到FullCalendar中的后台事件对象 [英] Passing data to background event object in FullCalendar
问题描述
当用户单击后台事件时,是否有办法获取传递给eventObj的数据? 我的示例背景事件如下所示:
Is there a way to get a data that I passed to eventObj when user clicks on background event? My sample background event looks like this:
{
id: 'availableForMeeting',
title: 'Test Background Event #1',
start: '2015-08-13T07:30:00',
end: '2015-08-13T12:30:00',
rendering: 'background',
sampleId: 214,
color: 'red'
}
但是我无法获取sampleId字段,因为它在jsEvent中不存在.
But I can't get sampleId field, 'cause it doesn't exist in jsEvent.
推荐答案
首先,为了实际获得后台事件的点击处理程序,您必须使用委托的jquery
First, in order to actually get a click handler on a background event, you have to use a delegated jquery .on()
because FullCalendar's eventClick
doesn't work for background events.
$("#calendar").on("click",".fc-bgevent",function(event){
console.log($(this).data());
});
仅此而已,您将获得一个空的控制台日志.我们需要将事件数据添加到event元素.我们可以在 eventRender
With just that, you will get an empty console log. We need to add the event data to the event element. We can do this in eventRender
eventRender: function(event,element,view){
$(element).data(event);
},
工作 JSFiddle
这篇关于将数据传递到FullCalendar中的后台事件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!