list Javascript events from a JSON in the Full Calendar (Events) library

Asked

Viewed 227 times

0

I have a variable where stores the result of a JSON through an AJAX request, as below:

$.ajax( 
    {
        url: 'endpoint',   
        method: 'GET',
        data: {
            action: 'getAgenda',
            keyuser: idLess
        },
        success: function(response){
            var dados_agenda = response;
        },
        dataType: 'json'
    }

);

giving a.log console on the date_agenda variable, I have the following JSON result:

{
    "id": "1",
    "title": "reuniãp",
    "start": "2019-03-19 10:00:00",
    "end": "2019-03-19 11:00:00",
    "situacao": "A",
    "cor": "#4761c5",
    "Update": "2019-03-17 16:24:00"
}{
    "id": "2",
    "title": "Churrasqueira",
    "start": "2019-03-20 10:00:00",
    "end": "2019-03-20 11:00:00",
    "situacao": "A",
    "cor": "#4761c5",
    "Update": "2019-03-17 18:17:00"
}

My difficulty is to play the JSON stored in the data_agenda variable, in the Events property of the Fullcalendar library, as below:

$(document).ready(function() {

   $('#calendar').fullCalendar({
     header: {
       left: 'prev,next today',
       center: 'title',
       right: 'month,basicWeek,basicDay'
     },
     defaultDate: '2019-03-12',
     navLinks: true, 
     editable: true,
     eventLimit: true, 
     events:[
    {
      id: 999,                     <- id entrar aqui
      title: 'All Day Event',      <- title entrar aqui
      start: '2019-01-01',         <- start entrar aqui
      end: '2019-03-07'            <- end entrar aqui
    },
    {
      id: 999,                     <- id entrar aqui
      title: 'Long Event',         <- title entrar aqui
      start: '2019-03-07',         <- start entrar aqui
      end: '2019-03-07'            <- end entrar aqui
    }
  ]

   });
});  

I couldn’t evolve the code until I got to that part. How could I go with the code?

1 answer

1


Utilize:

$('#calendar').fullCalendar('addEventSource', dados_agenda );

Documentation

There is only one error in your JSON: missing a comma separating objects: },{

  • I could put this script exactly in what code location ?

  • Down in Ajax, after var dados_agenda = response;.

  • Perfect dear friend, I’m going to do a test now. I’m going to adjust my Json

Browser other questions tagged

You are not signed in. Login or sign up in order to post.