Fullcalendar for HTML5 LocalStorage

Hi guys, I am using the jQuery full calendar plugin.

I wanted to save events and get through LocalStorage HTML5.

And I managed to store the part using JSON and got the element from the localstorage element using JSON Parse.

nw, when I loop through a JSON value (more than 50 values) and assign the same event object to its broken match.

Here is my loop (Sample)

var vEvents = '['; for(i=1; i<=1; i++) { vEvents += '{ "title": "new appointment", "start": "12-MAR-2012 14:00" }'; } vEvents += ']'; 

and this is assignin like this

 events: vEvents, 

Here is the o / p console log: -

 [{ "title": "new appointment", "start": "12-MAR-2012 14:00" }] 

Fullcalender does not extract the correct o / p values, whereas if I set it as shown below (static), it worked correctly.

 var vEvents = [{ "title": "new appointment", "start": "12-MAR-2012 14:00" }]; 

Please help me in more detail.

+4
source share
2 answers

Thanks for your efforts. This is how I store:

 calendar.fullCalendar('renderEvent',{title: title,start: start, end: end, allDay: allDay, description :'test', save : localStorage.setItem("iCals"+eventIdLocal, JSON.stringify({"title": title, "start": start,"end" : end , "allDay" : allDay })) } 

and I go back:

 var eventIdLocal = localStorage.getItem("getiCalsEventIdiCals"); var title; valeventsiCals = '['; for(i=1; i<=eventIdLocal; i++) { var numval = JSON.parse(localStorage.getItem("iCals"+i)); valeventsiCals += '{"id" :"'+i+'"', valeventsiCals += ',"title" :"'+numval.title+'"', valeventsiCals += ',"start" :"'+numval.start+'"'; if(i<eventIdLocal) valeventsiCals += "},"; } valeventsiCals +='}]'; 
0
source

In the first case, you simply add a line, while fullcalendar expects an object (so the second case works). Before saving data to localStorage just convert it to a JSON string.

 localStorage.eventsList = JSON.stringify(vEvents); 

And convert it back to object when retrieving from storage

 var events = JSON.parse(localStorage.eventsList); 
+1
source

Source: https://habr.com/ru/post/1403318/


All Articles