Fullcalendar,如何动态地将传递的参数更改为eventSource?

时间:2015-09-03 15:06:40

标签: jquery fullcalendar

我有以下代码来获取事件:

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

typeof($scope.calendar) == 'undefined' ? '1' : '2'仅评估一次的问题,以及以下所有请求通过相同id的问题。如何在每次通话时再次评估此表达式?

1 个答案:

答案 0 :(得分: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(将其放在函数内)。