2013-11-22 46 views
3

使用MySQL的Fullcalendar(資源分支)運行良好,插入。Fullcalendar - 如何立即將ID(從數據庫)進入事件?

然後移動&調整大小事件...但只有在頁面重新加載後。

我無法找到立即將db ID添加到事件的方式。結果是,當用戶創建一個事件並立即移動(或調整其大小)時,我無法更新數據庫。

我有mysql_insert_id回來了,似乎已經嘗試了一切,我知道得到它可用在那裏它需要的地方,可能是......

if (title) { 
       $.ajax({ 
          type: "POST", 
          url: "db_actions.php", 
          data: { 
          equipment_id: resource.id, 
          start: start, 
          end: end, 
          title: title, 
         } 
        }) 

        .done(function(id) { 
         alert("Resulting mysql_insert_id is " + id); 
         }); 

       calendar.fullCalendar('renderEvent', 
        { 
         title: title, 
         start: start, 
         end: end, 
         allDay: allDay, 
         resource: resource.id, 
         event_id:id 
        }, 
        true // make the event "stick" 
       ); 

有什麼想法?非常感激。

馬克

========================================= ====

更新...

啊哈!

一個簡單的答案...在回調內移動渲染器,允許訪問id變量。

if (title) { 
      $.ajax({ 
         type: "POST", 
         url: "db_actions.php", 
         data: { 
         equipment_id: resource.id, 
         start: start, 
         end: end, 
         title: title, 
        } 
       }) 

       .done(function(id) { 

        alert("Resulting mysql_insert_id is " + id); 

        calendar.fullCalendar('renderEvent', 
        { 
         title: title, 
         start: start, 
         end: end, 
         allDay: allDay, 
         resource: resource.id, 
         event_id:id 
        }, 
        true // make the event "stick" 
        ); 

      }); 

回答

1

只需將database_id作爲自定義屬性添加到fullcalendar事件對象即可。此屬性然後可用於任何fullcalendar方法,如「eventClick」,

我通常在接收AJAX調用的結果的「fillCalendar」方法中執行此操作。

fillCalendar(dbObjects) { 
    fcEvents = []; 
    ... 
    fcEvents.push({ 
     database_id: dbObjects[i].id, 
        title: title, 
        start: start, 
        end: end, 
        allDay: allDay, 
        resource: resource.id, 
        event_id:id 
    } 
    ... 
    return fcEvents; 

} 
相關問題