我想在我的Event Json Response中发送一个类型。
这是我的代码:
$('#calendar').fullCalendar({
eventSources: [
{"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
{"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}
]
});
您看到我在JSON Response数组中发送类型,这可能吗?我们可以使用什么参数来发送自定义数据?
答案 0 :(得分:12)
非标准字段
除上述字段外,您还可以在每个事件对象中包含您自己的非标准字段。 FullCalendar不会修改或删除这些字段。例如,开发人员通常会在eventRender等回调中包含
description
字段。
示例:强>
$('#calendar').fullCalendar({
events: [
{
title: 'My Event',
start: '2010-01-01',
type: 1 // Custom field
}
],
eventRender: function(event, element) {
console.log(event.type); // Writes "1"
}
});
答案 1 :(得分:9)
使用events:
代替eventSources:
$('#calendar').fullCalendar({
events: [
{"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
{"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}
]
});
答案 2 :(得分:3)
在版本4中,自定义数据位于 extendedProps 中。
简而言之e.event.extendedProps
答案 3 :(得分:0)
只要url返回json response
,您也可以将url端点传递给事件 cId.fullCalendar({
header: {
right: '',
center: 'prev, title, next',
left: ''
},
theme: true, //Do not remove this as it ruin the design
selectable: true,
selectHelper: true,
editable: true,
//it will load data from this url
events: "{{ url('api/events') }}",
// events: getData(),
//Add Events
});
并在你的控制器或功能中
$events = $request->user()->events()->select('title','color','date')->get();
// dd($even,$events)
$eventsResponse = [];
// created_at->format('Y-m-d')
foreach ($events as $event)
{
$eventsResponse[] = [
'title'=>$event->title,
'color'=>$event->color,
'start'=> Carbon::parse($event->date)->toDateTimeString(),
];
}
return $eventsResponse;
答案 4 :(得分:0)
在新版本中,您应该这样做:
eventRender: function (info) {
info.el.firstChild.innerHTML = info.event.extendedProps.type + " " + info.event.extendedProps.customEventsClass;
}