I'm using Fullcalendar V4 for a planning tool. Now I want to use the external events option. When I put the data in the div manually it works great. But I need to get the data from a JSON response. When I try this it won't work. I can't drag the events to the calendar and don't get any response. How do I get the data the right way in the div?
This is the code for the container
new Draggable(containerEl, {
itemSelector: '.fc-event',
eventData: function(eventEl) {
var obj=JSON.parse(eventEl.dataset.event);
return {
title: eventEl.innerText,
id: obj.id,
duration: obj.duration,
extra1: obj.extra1,
backgroundColor: obj.backgroundColor
};
} });
This are the divs I make manually
<div class='fc-event' data-event='{"title":"event title1","id":"1","duration":"11:45","extra1":"11.00","backgroundColor":"#D7EBFA"}'>My Event 1</div>
This is the code to get the data in the divs
var JsonData = [{"id":"1","title":"Event Title 1","duration":"00:45","extra1":"8.00","backgroundColor":"#D7EBFA"},{"id":"2","title":"Event Title 2","duration":"00:45","extra1":"8.00","backgroundColor":"#D7EBFA"}];
for (var i = 0; i < JsonData.length; i++) { $("#external-events").append('<div class="fc-event" data-event="{"title":"'+JsonData[i].title+'", "id":"'+JsonData[i].id+'", "duration":"'+JsonData[i].duration+'", "extra1":"'+JsonData[i].extra1+'", "backgroundColor":"'+JsonData[i].backgroundColor+'"}">'+JsonData[i].title+'</div>');}
And this makes the div like this
<div class="fc-event" data-event="{" title":"event title 1", "id":"1", "duration":"00:45", "extra1":"8.00", "backgroundcolor":"#d7ebfa"}">Event Title 1</div>
I think there should be a simple solution for this.
Thanks