Javascript JS日历JSON的Render属性
这是Javascript JS日历JSON的Render属性,javascript,jquery,html,json,calendar,Javascript,Jquery,Html,Json,Calendar,这是JS函数,用于初始化日历: function InitCalendar() { $('#calendar').fullCalendar({ events: { url: '/vacation/SchedulesGet', type: 'POST', data: { title: 'title',
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);
这是行动:
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);
}
public虚拟JsonResult SchedulesGet()
{
var vacationRequests=新列表();
foreach(服务.GetVacationRequestsWithProfiles().ToArray()中的变量项)
{
int vacationLength=((item.DateEnd-item.DateStart).Days+1);
弦日;
如果(假期长度>1)
day=“天”;
其他的
day=“day”;
vacationRequests.Add(新增)
{
start=item.DateStart,
end=item.DateEnd,
title=item.Profile.FirstName
+“”+item.Profile.LastName
+“(“+item.VacationType.Type”
+“)”+假期长度+天数,
//url=“/VacationRequest/Edit/”+item.Id
id=项目。id
});
}
返回Json(vacationRequests,JsonRequestBehavior.AllowGet);
}
我需要设置为
div
块数据id
属性。viewRender:function
中的所有其他函数都可以正常工作。但是使用这一行$('.fc content').attr('data-id',id)代码>日历不工作。有人可以帮我吗?您在哪里定义id
?请检查公共虚拟JsonResult SchedulesGet()。您没有提供足够的信息,因此很难帮助您。在SchedulesGet
中,您创建了JSON,但问题是viewRender
中的id
来自何处?我认为dfsq很好地说明了id,它似乎是最有可能的失败点。建议使用脚本调试器检查该值,以确保已定义该值。您还可以尝试对一个id进行编码,以查看它是否能够正常工作。