2016-05-26 5 views
0

イベントをFullCalendarプラグインに入れようとしています。 AJAXコールでは、C#WebMethodを使用してデータベース内のレコードを取得し、WebMethodからdifferentsイベントの配列を返します。ここでAJAXを使用してFullCalendarにイベントを設定するにはどうすればよいですか?

カレンダーの表示に私のAjaxです:

var source = []; 
$.ajax({ 
    type: 'POST', 
    url: "Default.aspx/GetEvents", 
    dataType: "json", 
    contentType: "application/json; charset=utf-8", 
    data: '{ userId: 1}', 
    success: function (doc) { 
     source = [doc.d[0], doc.d[1], doc.d[2]]; 

     $('#calendar').fullCalendar({ 
      header: { 
       left: 'prev,next today', 
       center: '', 
       right: 'month,basicWeek, agendaFourDay', 
      }, 
      views: { 
       agendaFourDay: { 
        type: 'agenda', 
        duration: { week: 1 }, 
        buttonText: '7 day' 
       } 
      }, 
      height: 650, 
      dayClick: function (date, view) { 
       alert('Clicked on: ' + date.format()); 
       alert('Current view: ' + view.name); 
       // change the day's background color just for fun 
       $(this).css('background-color', 'red'); 
       $("#AddNew").css("display", "block"); 
       $("#stDate").val(date.format('DD/MM/YYYY')); 
      }, 
     }); 
     alert(source); 
     $('#calendar').fullCalendar('renderEvent', source, true); 
     $('#calendar').fullCalendar('addEventSource', source); 
     $('#calendar').fullCalendar('refetchEvents');   
    } 
}); 

その後、私のコードC#:

TypeError: eventProps.start is undefined 


eventProps.allDay = !(eventProps.start.hasTime() || (eventProps.end && eventProp... 

マイ:

[System.Web.Services.WebMethod] 
    public static string[] GetEvents(int userId) 
    { 
     string sql; 
     Recordset rst = new Recordset(); 


     string eventName = null; 
     string stDate = null; 
     string edDate = null; 
     int j = 0; 

     if (AppCode.Utils.DB_Connect()) 
     { 
      sql = "SELECT * FROM events WHERE Users_idUsers = 1"; 
      rst.Open(sql, AppCode.Utils.ocn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockOptimistic, -1); 

      if(!rst.EOF) 
      { 
       while (!rst.EOF) 
       { 
        eventName += rst.Fields["EventName"].Value.ToString() + '#' + rst.Fields["StartDate"].Value.ToString() + '#' + rst.Fields["EndDate"].Value.ToString()+'&';      
        rst.MoveNext(); 
        j++; 
       } 

      } 
      if (rst.State > 0) 
       rst.Close(); 

     } 
     AppCode.Utils.DB_Disconnect(); 

     eventName = eventName.Substring(0, eventName.Length - 1); 
     string[] events = eventName.Split('&'); 

     string final = ""; 

     foreach (var item in events) 
     { 
      string[] elements = item.Split('#'); 
      DateTime dt = new DateTime(); 
      dt = Convert.ToDateTime(elements[1]); 
      stDate = dt.ToString("yyyy-MM-dd"); 

      DateTime ft = new DateTime(); 
      ft = Convert.ToDateTime(elements[2]); 

      edDate = ft.ToString("yyyy-MM-dd");    

      final += "{ title: '" + elements[0] + "',start: '" + stDate + "',end: '" + edDate + "'}#"; 
     } 

     final = final.Substring(0, final.Length - 1); 
     string[] eventsArray = final.Split('#'); 
     return eventsArray; 
    } 

Firebugのは、エラーがあると言いますたとえば、d [0]は次のようになります。

"{ title: 'aaa',start: '2016-12-11',end: '2016-12-11'}" 

このエラーを解決する方法はありますか?私は間違った方法でいるかもしれませんか?または、イベントを表示するための他の問題がありますか? 私は

答えて

0

は、すべてのデータは、あなたがそれを動作させるために行う必要がある唯一の事は

を削除することが有効であると仮定すると、..インターネットから多くのことを検索し、FullCalendarのドキュメントが、私は解決策を見つけることができません。
$('#calendar').fullCalendar('renderEvent', source, true); 
$('#calendar').fullCalendar('addEventSource', source); 
$('#calendar').fullCalendar('refetchEvents');   

、代わりにこれだけ

$('#calendar').fullCalendar('addEventSource', source); 

を保つには、私はeventSourcesを使用してfullCalendarの初期化中にAJAX呼び出しを使用することをお勧めいたしますだろう、と述べました。

"eventSources配列には、任意の数のイベント配列、関数、JSONフィードURL、またはフルアウトイベントソースオブジェクトを配置できます。

あなたは、現在のビューで機能やフィルタ日付を使用して、おそらくよいでしょう(とイベントの歴史全体をロードしない)ので、それはあなたが調整する必要があることを覚えておいてください(ビューに応じて自動的にそれをレンダリングしますそれをサポートするサーバー機能)。