0

您好 Fullcalendar 追随者,我正在尝试利用服务器端的线程将事件加载到日历中,以便在加载事件时获得更好的性能,这意味着:

1 - 我只有一个 evenSource 提要:

eventSources: [othersources.funcmap] //Employee calendar MAP

2 - 在 Servlet 中(我正在处理 java ):

I am gathering all JSON objets from different sources and joining them together in one large big object (with threads) that i want to send back to Fullcalendar.

2.1 - 如果我单独发送它们(多个 ajax 调用含义 [othersources.vacations,othersources.faults 等...])有字符串(JSON 格式)它们工作正常并且所有提要都已加载。

 This is the JSON object in the "individual" String -> `[{"title":"Vacation day","start":"02-09-2013", etc etc etc}]`

问题

问题是当我将它们连接在一起时,我会制作这样的对象:

[ 
   [{"title":"Vacation day","start":"02-09-2013", etc etc etc},{"title":"Vacation day","start":"02-09-2013", etc etc etc}],
   [{"title":"Fault day","start":"02-09-2013", etc etc etc},{"title":"Faul day","start":"02-09-2013", etc etc etc}],
   [{"title":"Birthday fault","start":"02-09-2013", etc etc etc},{"title":"Birthday fault","start":"02-09-2013", etc etc etc}]

 ]

这实际上是一个有效的 JSON 对象(当然没有“etc etc etc”:P),但它不起作用。fullcalendar 不会呈现事件...

我怎样才能将它们连接到一个 Fullcalendar 理解的大对象中?还是 Fullcalendar 只知道如何读取简单的 JSON 对象?

先感谢您。

4

2 回答 2

1

The easiest solution would probably be to flatten the events array before handing it to FullCalendar. But if you insist, then it is also possible by providing a function as a event source in FullCalendar.

The documentation for the function is here: http://arshaw.com/fullcalendar/docs/event_data/events_function/

And this is the basic way to do it:

eventSources: [function (start, end, callback) {

    var eventArrays = [
        [{
            "title": "Vacation day",
            "start": new Date()
        }, {
            "title": "Vacation day",
            "start": new Date()
        }],
        [{
            "title": "Fault day",
            "start": new Date()
        }, {
            "title": "Faul day",
            "start": new Date()
        }],
        [{
            "title": "Birthday fault",
            "start": new Date()
        }, {
            "title": "Birthday fault",
            "start": new Date()
        }]
    ];

    // Using underscore.js to flatten the array
    var events = _.flatten(eventArrays);

    callback(events);
}]

You can check out a working example here: http://jsfiddle.net/kvakulo/q5HET/1/

于 2013-07-10T16:42:09.980 回答
0

最后,这根本没有意义。多次 AJAX 调用比尝试在 servlet 中使用线程返回所有调用更快。

但它适用于 Flat JSON,我只是将它们全部连接在一起 [{},{}...],没有子数组。

于 2013-07-11T15:29:20.380 回答