2015-12-21 69 views
0

我正在使用Fullcalendar。我现在通过拖放来创建活动。我想在一天中双击一下。我正在尝试使用dayRendar函数,但“event.start.format()”未定义。任何人都可以检查我的代码,我错了什么?由于Fullcalender dayRender

dayRender: function(event, element) { 
      element.bind('dblclick', function(event,element) { 
        var title = prompt('Event Title:', event.title, { buttons: { Ok: true, Cancel: false} }); 
         if (title){ 
         console.log(event); 
          event.title = title; 
          var start = event.start.format("YYYY-MM-DD[T]HH:MM:SS"); 
          $.ajax({ 
           url: '{!!URL::route("saveCalendarEvent")!!}', 
           data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone, 
           type: 'POST', 
           dataType: 'json', 
           success: function(response){  
           event.id = response.eventid; 
           $('#calendar').fullCalendar('updateEvent',event); 
           }, 
           error: function(e){ 
            alert('Error processing your request: '+e.responseText); 
           } 
          }); 
         } 

      }); 
     } 

错误:

Uncaught TypeError: Cannot read property 'format' of undefined 

回答

0

的的DayRender参数是日期和细胞,而不是事件和元素:

按照FullCalendar Docs为的DayRender:

function(date, cell) { } 

所以问题是,你的'元素'变量实际上是一个日期,所以'event.start'没有存在因此抛出一个错误,当你打电话'event.start.format'

+0

那么我现在应该做什么scottysmalls? –

+0

首先更改功能参数。然后在你的ajax中使用你提示中的标题作为dayRender回调中的标题和'date'。 (类似于var start = date.format(“YYYY-MM-DD [T] HH:MM:SS”); – scottysmalls