2015-09-03 18 views
1

我有一個下面的代碼以獲取事件:Fullcalendar,如何動態地將傳遞的參數更改爲eventSource?

var eventSource = { 
      url: 'api/events/get/byrange', 
      data: { 
       id: typeof($scope.calendar) == 'undefined' ? '1' : '2' 
      } 
    }; 

typeof($scope.calendar) == 'undefined' ? '1' : '2'只計算一次,所有的以下請求它傳遞一個相同id的問題。我怎樣才能讓它在每次通話中再次評估這個表情?

+0

你可以創建兩個資源,然後以編程方式顯示或隱藏它們嗎?與此類似:http://stackoverflow.com/questions/10940182/change-fullcalendar-event-source-after-render –

回答

1

你需要寫

{ 
     url: 'api/events/get/byrange', 
     data: { 
      id: typeof($scope.calendar) == 'undefined' ? '1' : '2' 
     } 
}; 

沒有在一個變量var eventSource設置它。相反,只需在FullCalendar初始化中附加這段代碼即可。

但是,我不使用這種方法。相反,我對返回對象列表的操作執行JSON請求。

的Javascript:

$.getJSON('GetCalendar?TrainingId=' + $('#TrainingId').val(), function (response) { 
    $('#CalendarWrapper').empty(); 
    $('#CalendarWrapper').append("<div id='calendar' name='calendar'></div>"); 
    window.events = response; 
    window.calendar = $('#calendar').fullCalendar({ 
     header: { 
      left: 'prev,next today', 
      center: 'title', 
      right: 'month,agendaWeek,agendaDay' //, basicWeek,basicDay 
     }, 
     selectHelper: true, 
     allDaySlot: false, 
     slotDuration: '00:15:00', 
     buttonIcons: true, // show the prev/next text 
     weekNumbers: false, 
     editable: true, 
     selectOverlap: true, 
     unselectAuto: true, 
     eventLimit: true, // allow "more" link when too many events 
     lang: GetFullCalendarLanguage(), 
     aspectRatio: 2.5, 
     events: window.events, 
    }); 

    _CalendarBuild = true; 
}) 

操作:

[HttpGet] 
public JsonResult GetCalendar(int TrainingId) 
{ 
    var model = QUERY 
     .Select(x => new FullCalendar 
     { 
      title = x.Module.Description + ", " + x.Local.Info, 
      Day = x.Day, 
      (...) 
     }) 
     .ToList(); 

    return Json(model, JsonRequestBehavior.AllowGet); 
} 

FullCalendar:

public class FullCalendar 
{ 
    public virtual string title { get; set; } 

    public virtual string url { get; set; } 

    public virtual DateTime Day { get; set; } 

    public virtual string start { get; set; } 

    public virtual string end { get; set; } 

    public virtual bool startEditable { get; set; } 
} 

而當我想再次渲染我只需再次調用JavaScript(這是放置在函數內部)。

相關問題