jquery - 如何编辑全日历事件内容

标签 jquery fullcalendar

我成功地将 fullcalendar 控件嵌入到我的 asp.net mvc 应用程序中。它运行完美。但我想编辑现有的事件,我必须做什么?

编辑: 好的,我已经在 fullcalender 控件中成功编辑了事件。但编辑事件后,它会将其视为新事件,而不是替换另一个事件,它会向我显示另一个事件。如果我刷新页面,它就会正确显示。所以我想在编辑事件后,我想如何渲染/再次调用/刷新页面。

这是代码:

  $(document).ready(function() {
      var date = new Date();
      var d = date.getDate();
      var m = date.getMonth();
      var y = date.getFullYear();
      var officerid = document.getElementById('officerid').value;
      url = "/TasksToOfficer/Calender/" + officerid;


      var calendar = $('#calendar').fullCalendar({
          header: {
              left: 'prev,next today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay',
              border: 0
          },
         eventClick: function(calEvent, jsEvent, view) {

              var title = prompt('Event Title:', calEvent.title, { buttons: { Ok: true, Cancel: false} });

              if (title) {
                  var st = calEvent.start;
                  var ed = calEvent.end;
                  var aldy = calEvent.allDay;
                  var dt = calEvent.date;
                  var iden = calEvent.id;

                  calendar.fullCalendar('renderEvent',
                                           {
                                               title: title,
                                               start: st,
                                               end: ed,
                                               allDay: aldy
                                           },
                                           true);


                  var date = new Date(st);
                  var NextMonth = date.getMonth() + 1;
                  var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();



                  if (officerid) {
                      $.ajax(
                                                    {

                                                        type: "POST",
                                                        url: "/TasksToOfficer/Create",
                                                        data: "officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=true&EventId=" + iden,
                                                        success: function(result) {

                                                            if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success

                                                        },
                                                        error: function(req, status, error) {

                                                        }
                                                    });


                  }
              }

          }

              ,

          selectable: true,
          selectHelper: true,
          select: function(start, end, allDay) {
              var title = prompt('Event Title:', { buttons: { Ok: true, Cancel: false }

              });
              if (title) {
                  calendar.fullCalendar('renderEvent',
                                                                 {
                                                                     title: title,
                                                                     start: start,
                                                                     end: end,
                                                                     allDay: allDay
                                                                 },
                                              false); // This is false , because do not show same event on same date after render from server side.
                  var date = new Date(start);

                  var NextMonth = date.getMonth() + 1; // Reason: it is bacause of month array it starts from 0

                  var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();

                  if (officerid) {
                      $.ajax(
                                                                    {

                                                                        type: "POST",
                                                                        url: "/TasksToOfficer/Create",
                                                                        data: "officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=false",
                                                                        success: function(result) {

                                                                            if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success
                                                                            //$("#feedback_status").slideDown(250).text(result.message); // show status message with animation
                                                                        },
                                                                        error: function(req, status, error) {

                                                                        }
                                                                    });
                  }
              }
              calendar.fullCalendar('unselect');
          },
          editable: true,
          lazyFetching: true,
          events: url //this will call the action from controller and show the saved events in db, the result of the action should be in proper formate.
      });
  });

我在这里尝试使用 refetchEvent、renderEvents 进行回调,但没有成功。还有其他问题吗?

最佳答案

您必须调用updateEvent,而不是调用renderEvent当你改变一个的时候。另请注意,您必须向 updateEvent 提供“真实”日历事件,而不是您编写的事件。所以你的代码应该像这样:

eventClick: function(calEvent, jsEvent, view) {
          var title = prompt('Event Title:', calEvent.title, { buttons: { Ok: true, Cancel: false} });

          if (title){
              calEvent.title = title;
              calendar.fullCalendar('updateEvent',calEvent);
          }
}

关于jquery - 如何编辑全日历事件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4395786/

相关文章:

javascript - 根据 li JQuery 中输入元素的值删除元素 li

javascript - 将 $FILE 数据发送到表单输入

jquery调用webservice失败

php - 显示全天事件的完整日历

javascript - 显示 06 :00 instead of 6am in FullCalendar

javascript - jqgrid 中的复选框选中或取消选中

javascript - 一次显示折叠内容

php - jQuery fullCalendar dayClick - 将(日期)转换为 mm/dd/yy

javascript - 避免 FullCalendar 中的事件叠加

javascript - 如何预测或获取默认的 fullCalendar firstDay