简体   繁体   English

在javascript完整日历上添加事件

[英]adding events on javascript Full calendar

I have a system which needs a full calendar to display the upcoming events. 我的系统需要完整的日历才能显示即将发生的事件。 I successfully migrated it with my angularjs app and the calendar is working fine. 我已使用我的angularjs应用程序成功迁移了它,并且日历运行正常。 My problem is, I can't display a custom event from the database using a JSON format. 我的问题是,我无法使用JSON格式显示数据库中的自定义事件。 To properly explain it here's the code: 为了正确解释,下面是代码:

    //Date for the calendar events (dummy data)
 var date = new Date();
 var d = date.getDate(),
     m = date.getMonth(),
     y = date.getFullYear();
 var evts = '['; // variable for events
 //this is the part  where i tested to create a json format
 for (var i = 1; i <= 3; i++) {
     if (i < 3) evts = evts + '{"title":"John", "start": "new Date(y, m, ' + i + ')", "backgroundColor":"#f56954", "borderColor":"#f56954"},';
     else evts = evts + '{ "title":"John", "start": "new Date(y, m, ' + i + ')", "backgroundColor":"#f56954", "borderColor":"#f56954"}]';
 }
 $('#calendar').fullCalendar({
     header: {
         left: 'prev,next today',
         center: 'title',
         right: 'month,agendaWeek,agendaDay'
     },
     buttonText: {
         today: 'today',
         month: 'month',
         week: 'week',
         day: 'day'
     },
     events: evts, // here's the event to be added... i try this but no event is showing
     /* this are the proper format of adding events this is also what i did in the json format
          {
          title: test,
          start: new Date(y, m, 1),
          backgroundColor: "#f56954", //red
          borderColor: "#f56954" //red
        },
        {
          title: 'Kalag-kalag',
          start: new Date(y, m, 14),
          backgroundColor: "#f56954", //red
          borderColor: "#f56954" //red
        },
        {
          title: 'National Ero\'s day',
          start: new Date(y, m, d - 5),
          end: new Date(y, m, d - 2),
          backgroundColor: "#f39c12", //yellow
          borderColor: "#f39c12" //yellow
        },
        {
          title: 'Araw ng mga patay',
          start: new Date(y, m, d, 10, 30),
          allDay: false,
          backgroundColor: "#0073b7", //Blue
          borderColor: "#0073b7" //Blue
        },
        {
          title: 'Break-up day :(',
          start: new Date(y, m, d, 12, 0),
          end: new Date(y, m, d, 14, 0),
          allDay: false,
          backgroundColor: "#00c0ef", //Info (aqua)
          borderColor: "#00c0ef" //Info (aqua)
        },
        {
          title: 'Lonely birthday',
          start: new Date(y, m, d + 1, 19, 0),
          end: new Date(y, m, d + 1, 22, 30),
          allDay: false,
          backgroundColor: "#00a65a", //Success (green)
          borderColor: "#00a65a" //Success (green)
        },
        {
          title: 'Suicidal day',
          start: new Date(y, m, 28),
          end: new Date(y, m, 29),
          url: 'http://google.com/',
          backgroundColor: "#3c8dbc", //Primary (light-blue)
          borderColor: "#3c8dbc" //Primary (light-blue)
        }
      ],*/
     editable: true,
     droppable: true, // this allows things to be dropped onto the calendar !!!
     drop: function(date, allDay) { // this function is called when something is dropped

         // retrieve the dropped element's stored Event Object
         var originalEventObject = $(this).data('eventObject');

         // we need to copy it, so that multiple events don't have a reference to the same object
         var copiedEventObject = $.extend({}, originalEventObject);

         // assign it the date that was reported
         copiedEventObject.start = date;
         copiedEventObject.allDay = allDay;
         copiedEventObject.backgroundColor = $(this).css("background-color");
         copiedEventObject.borderColor = $(this).css("border-color");

         // render the event on the calendar
         // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
         $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

         // is the "remove after drop" checkbox checked?
         if ($('#drop-remove').is(':checked')) {
             // if so, remove the element from the "Draggable Events" list
             $(this).remove();
         }

     }
 });

when i run the app it doesn't show any events from the calendar but the calendar is showing fine. 当我运行该应用程序时,它没有显示日历中的任何事件,但日历显示正常。 I already did my best on fixing it and I realized I really need someone to give me idea on how to show event from a javascript full calendar using JSON format. 我已经尽了最大的努力来解决它,我意识到我真的需要有人给我关于如何使用JSON格式显示来自javascript完整日历的事件的想法。 Any idea will greatly be appreciated. 任何想法将不胜感激。

Your approach is not proper to of making events. 您的方法不适合进行事件。

Try this one. 试试这个。

var date = new Date();
var d = date.getDate(),
 m = date.getMonth(),
 y = date.getFullYear();
var evts = []; // variable for events
//this is the part  where i tested to create a json format
for (var i = 1; i <= 3; i++) {
    evts.push({
        title: "John",
        start: new Date(y, m, i),
        backgroundColor: '#f56954',
        borderColor: '#f56954'
    });
}

And then set this evts in your fullcalendar configuration. 然后在您的全日历配置中设置此评估。

events: evts,

This works fine. 这很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM