[英]Fullcalendar one feed with multiple JSON objects
您好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 FORMAT),则它们工作正常,并且所有提要均已加载。
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对象(当然没有:P的“ etc etc etc”),但是它不起作用。 fullcalendar不会渲染事件...
我如何将他们一起加入Fullcalendar理解的一个大对象中? 还是Fullcalendar只知道如何读取简单的JSON对象?
先感谢您。
最简单的解决方案可能是在将事件数组移交给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/
最后,这根本没有任何意义。 多个AJAX调用比尝试进行一次即使在servlet中的线程返回全部返回时都更快。
但是它与Flat JSON一起使用时,我只是将它们全部合并在一起[{},{} ...],没有子数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.