将属性渲染到JS日历JSON

时间:2015-05-08 14:22:37

标签: javascript jquery html json calendar

这是JS函数,用于初始化日历:

function InitCalendar() {
    $('#calendar').fullCalendar({
        events: {
            url: '/vacation/SchedulesGet',
            type: 'POST',
            data: {
                title: 'title',                      
                id : 'id',
                start: new Date('start'),
                end: new Date('end'),
            },
            error: function () {
                alert('there was an error while fetching events!');
            },
            color: 'yellow',
            textColor: 'black'
        },
        viewRender: function () {
            $('.fc-content').attr('data-id', id);

这是Action

public virtual JsonResult SchedulesGet()
        {
            var vacationRequests = new List<dynamic>();

            foreach (var item in _service.GetVacationRequestsWithProfiles().ToArray())
            {
                int vacationLength = ((item.DateEnd - item.DateStart).Days + 1);
                string day;
                if (vacationLength > 1)
                    day = " days";
                else
                    day = " day";
                vacationRequests.Add(new
                {
                    start = item.DateStart,
                    end = item.DateEnd,
                    title = item.Profile.FirstName
                            + " " + item.Profile.LastName
                            + " (" + item.VacationType.Type
                            + ") " + vacationLength + day,                    
                    //url = "/VacationRequest/Edit/" + item.Id
                    id = item.Id
                });
            }

            return Json(vacationRequests, JsonRequestBehavior.AllowGet);
        } 

我需要设置为divdata-id属性。 viewRender: function中的所有其他功能都可以正常工作。但是使用此行$('.fc-content').attr('data-id', id);日历不起作用。愿任何人帮助我吗?

0 个答案:

没有答案