简体   繁体   English

更改FullCalendar jQuery插件中的默认事件单元格视图

[英]Change the default event cell view in FullCalendar jQuery plugin

Maybe is an obvious question but I search on FullCalendar API, SO and google with no results. 也许是一个明显的问题,但我在FullCalendar API,SO和google上搜索,但没有结果。 I wondering if I can change the default cell view of every event into the FullCalendar? 我想知道是否可以将每个事件的默认单元格视图更改为FullCalendar?

For example my current events cell are only showing the time and the title I parsed from the data object. 例如,我的当前事件单元格仅显示从数据对象解析的时间和标题。 When I try to parse more data in the object I cannot display them into the calendar cell 当我尝试解析对象中的更多数据时,无法将其显示在日历单元格中

events: [
    {
        title: 'All Day Event',
        start: '2015-02-01'
        morecontent : 'MORE CONTENT' // How to display this??
    },
    {
        title: 'Long Event',
        start: '2015-02-07',
        end: '2015-02-10'
        morecontent : 'MORE CONTENT' // and this??
    }
];

You can change the cell during the eventRender , which is triggered when the event is being rendered ( docs ). 您可以在eventRender期间更改单元格,该事件在呈现事件( docs )时触发。

Something like the code below will find the title for that specific event and replace the html with the title + the more content: 类似于下面的代码,将找到该特定事件的标题,并将html替换为标题+更多内容:

eventRender: function(event, element) {
    $(element).find('.fc-title').html(event.title + ', ' + event.morecontent);
}

Here's a working version: 这是一个工作版本:

 $('#fullCal').fullCalendar({ events: [{ title: 'Random Event 1', start: moment().add(-4, 'h'), end: moment().add(-2, 'h'), morecontent: 'Eat Pizza', allDay: false }, { title: 'Random Event 2', start: moment().add(1, 'd'), end: moment().add(2, 'd'), morecontent: 'Drink Coffee', allDay: false }, { title: 'Random Event 3', start: moment().add(6, 'd'), end: moment().add(8, 'd'), morecontent: 'Hackathon', allDay: false }], header: { left: '', center: 'prev title next today', right: '' }, eventRender: function(event, element) { $(element).find('.fc-title').html(event.title + ', ' + event.morecontent); }, timezone: 'local' }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script> <div id="fullCal"></div> 

It seems like so far, your JSON (from the database) is creating the code you provided above. 到目前为止,您的JSON(来自数据库)似乎正在创建您上面提供的代码。 If so, then whatever its in morecontent should already be passed as a result to your fullcalendar object. 如果是这样,那么它的morecontent任何morecontent都应该已经作为结果传递给了您的fullcalendar对象。

To test use: 要测试使用:

eventClick: function(calEvent, jsEvent, view) {
     console.log(calEvent);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM