Fullcalendar一个包含多个JSON对象的提要

时间:2013-07-10 13:45:30

标签: java json multithreading servlets fullcalendar

Hello Fullcalendar粉丝,我正在尝试利用服务器端的线程将事件加载到日历中,这样我就可以在加载事件时获得更好的性能,这意味着:

1 - 我只有一个偶数源:

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”ofcourse:P)但它不起作用。 fullcalendar不会呈现事件......

我如何将它们连接在Fullcalendar理解的一个大对象中? 或者Fullcalendar只知道如何读取简单的JSON对象?

提前谢谢。

2 个答案:

答案 0 :(得分:1)

最简单的解决方案可能是在将事件数组交给FullCalendar之前将其展平。但是如果你坚持,那么也可以通过在FullCalendar中提供一个函数作为事件源。

该功能的文档位于:http://arshaw.com/fullcalendar/docs/event_data/events_function/

这是实现它的基本方法:

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);
}]

您可以在此处查看一个有效的示例:http://jsfiddle.net/kvakulo/q5HET/1/

答案 1 :(得分:0)

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

但它与Flat JSON一起工作我只是将它们加在一起[{},{} ...]没有子阵列。