将数据从数据库映射到JSON对象Fullcalendar [英] Mapping data from database into a JSON object Fullcalendar

查看:190
本文介绍了将数据从数据库映射到JSON对象Fullcalendar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Fullcalendar捆绑包(Symfony2),并且我添加的所有事件均正确显示。现在,我在Fullcalendar.js中添加 eventClick 函数(它与 open.window('page')一起用于测试) )。现在,我想在 alert()或其他方式(而不是)中获取有关此事件的所有信息(id,name等)。 window.open()

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().

我该怎么做?

$(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

});
});


推荐答案

如果您阅读event文档,请点击 https://fullcalendar.io/docs/mouse/eventClick/ 它向您显示可用于回调,其中包含一个事件对象,其中包含单击的事件的详细信息。

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);
}

您可以在此处找到事件对象的更多属性: https://fullcalendar.io/docs/event_data/Event_Object/ ,以防您想使用其他有关事件。

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.

这篇关于将数据从数据库映射到JSON对象Fullcalendar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆