Mapping data from database into a JSON object Full

2019-08-06 18:57发布

I've installed Fullcalendar bundle (Symfony2) and all the events that I'm adding were showing correctly. Now I add eventClick function in Fullcalendar.js (it works with open.window('page') just for testing). Now I want to get all the information about this event (id,name,...etc) in an alert() or something else instead of window.open().

How can I do that?

$(function () {
/* initialize the calendar
 -----------------------------------------------------------------*/
//Date for the calendar events (dummy data)
var date = new Date();
var d = date.getDate(),
    m = date.getMonth(),
    y = date.getFullYear();
$('#calendar-place').fullCalendar({
    monthNames: ["Janvier","Février","Mars","Avril","Mai","Juin","Julliet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre" ],
    monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jun','Jul','Aou','Sep','Oct','Nov','Dec'],
    dayNames: [ 'Diamnche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
    dayNamesShort: ['Diu','Dill','Dim','Dix','Dij','Div','Dis'],

    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    buttonText: {
        today: 'today',
        month: 'month',
        week: 'week',
        day: 'day'
    },
    events:
    {
        url:Routing.generate('fullcalendar_loadevents', { month: moment().format('MM'), year: moment().format('YYYY') }),
        color: '#45b2ea',
        textColor:'white',

        error: function() {
            alert('Error receving events');
        }
    },
    viewRender: function (view, element) {
        var month = view.calendar.getDate().format('MM');
        var year = view.calendar.getDate().format('YYYY');
    },

    eventClick: function() {

       window.open('login')
    },





    eventDrop: function(event,delta,revertFunc) {
        var newStartData = event.start.format('YYYY-MM-DD');
        var newEndData = (event.end == null) ? newStartData : event.end.format('YYYY-MM-DD');

        $.ajax({
            url: Routing.generate('fullcalendar_changedate'),
            data: { id: event.id, newStartData: newStartData,newEndData:newEndData  },
            type: 'POST',
            dataType: 'json',
            success: function(response){
                console.log('ok');
            },
            error: function(e){
                revertFunc();
                alert('Error processing your request: '+e.responseText);
            }
        });

    },
    eventResize: function(event, delta, revertFunc) {

        var newData = event.end.format('YYYY-MM-DD');
        $.ajax({
            url: Routing.generate('fullcalendar_resizedate'),
            data: { id: event.id, newDate: newData },
            type: 'POST',
            dataType: 'json',
            success: function(response){
                console.log('ok');
            },
            error: function(e){
                revertFunc();
                alert('Error processing your request: '+e.responseText);
            }
        });

    },
    editable: true

});
});

1条回答
神经病院院长
2楼-- · 2019-08-06 19:51

If you read the documentation of eventClick at https://fullcalendar.io/docs/mouse/eventClick/ it shows you the parameters available to the callback, which includes an "event" object containing details of the clicked event.

So you can do something like this:

eventClick: function( event, jsEvent, view ) 
{ 
  alert(event.title);
}

You can find more properties of the event object here: https://fullcalendar.io/docs/event_data/Event_Object/ in case you want to use other information about the event.

查看更多
登录 后发表回答