[英]Upload Events from Database to FullCalendar
I want to render events that are saved in the database to the Calendar Template. 我想将数据库中保存的事件呈现到日历模板。 All the events are passed as objects and can be retrieved like so:
所有事件都作为对象传递,可以像这样检索:
{% for object in objects %}
var start = "{{ object.start }}";
var end = "{{ object.end }}";
var name = "{{ object.name }}";
{% endfor %}
I can confirm this is working because I see it in Sources
tab when I inspect the page. 我可以确认这是可行的,因为我在检查页面时在“
Sources
选项卡中看到了它。 So I have a few events stored in the database and I want to render these events. 因此,我在数据库中存储了一些事件,我想呈现这些事件。
So looking at the documentation , I thought about doing something like this: 因此,在查看文档时 ,我想到了做这样的事情:
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
events: [ // put the array in the `events` property
{% for object in objects %}
var start = "{{ object.start }}"; // Can't seem to identify this statement
var end = "{{ object.end }}";
var name = "{{ object.name }}";
var event={id:1 , title: name, start: start, end:end};
//$('#calendar').fullCalendar( 'renderEvent', event, true);
{
title : name,
start : start,
end : end,
}
{% endfor %}
]
}
// any other event sources...
]
});
But the events
array returns empty shown in the Sources
inspect tab. 但是,
events
数组返回的空值显示在“ Sources
检查标签中。 I have been stuck on this for quite a while. 我已经坚持了很长时间。 Any ideas?
有任何想法吗?
EDIT: 编辑:
If I do something like this: 如果我做这样的事情:
select: function(start,end){
{% for object in objects %}
var name = "{{ object.name }}";
var start = "{{ object.start }}";
var end = "{{ object.end }}";
var event={id:1 , title: name, start: start, end:end};
$('#calendar').fullCalendar( 'renderEvent', event, true);
{% endfor %}
The events will show if I click on a date. 如果单击日期,将显示事件。 So I think if I wrap in a
function
it'll work. 因此,我认为如果我包装一个
function
它将起作用。 With that being said, is there like a initialize()
function in fullcalendar? 话虽这么说,fullcalendar中是否有像
initialize()
函数?
Found a solution: 找到一个解决方案:
loading: function(bool){
{% for object in objects %}
if (bool){
var name = "{{ object.name }}";
var start = "{{ object.start }}";
var end = "{{ object.end }}";
var event={id:1 , title: name, start: start, end:end};
$('#calendar').fullCalendar( 'renderEvent', event, true);
}
{% endfor %}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.