javascript Fullcalendar - 我们可以将自定义数据添加到我们的事件 Json 数据中吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20542056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fullcalendar - Can we add custom data to our event Json Data?
提问by HybrisHelp
I want to send a type in my Event Json Response.
我想在我的事件 Json 响应中发送一个类型。
Here is my code:
这是我的代码:
$('#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}
]
});
You see I send a typein JSON Response array, is this possible? What parameter can we use for sending our custom data?
你看我在 JSON 响应数组中发送一个类型,这可能吗?我们可以使用什么参数来发送我们的自定义数据?
回答by jensgram
As per the documentation:
根据文档:
Non-standard Fields
In addition to the fields above, you may also include your own non-standard fields in each Event Object. FullCalendar will not modify or delete these fields. For example, developers often include a
description
field for use in callbacks such as eventRender.
非标准字段
除了上述字段,您还可以在每个事件对象中包含您自己的非标准字段。FullCalendar 不会修改或删除这些字段。例如,开发人员通常包含一个
description
用于回调的字段,例如eventRender。
Example:
例子:
$('#calendar').fullCalendar({
events: [
{
title: 'My Event',
start: '2010-01-01',
type: 1 // Custom field
}
],
eventRender: function(event, element) {
console.log(event.type); // Writes "1"
}
});
回答by HybrisHelp
Try It with events:
instead of eventSources:
试试它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}
]
});
回答by MatuDuke
In the new version you should do this:
在新版本中,您应该这样做:
eventRender: function (info) {
info.el.firstChild.innerHTML = info.event.extendedProps.type + " " + info.event.extendedProps.customEventsClass;
}
回答by Ronald Araújo
In version 4 custom data is in extendedProps.
在第 4 版中,自定义数据位于extendedProps 中。
In short e.event.extendedProps
简而言之 e.event.extendedProps
回答by levis
You can also pass url endpoint to events as long as the url returns json response
您也可以将 url 端点传递给事件,只要 url 返回 json 响应
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
});
and in your controller or function
并在您的控制器或功能中
$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;