代码改变世界

fullcalendar踩过的坑

2019-01-04 17:16  马尔代夫_珍  阅读(1612)  评论(0编辑  收藏  举报

1、fullcalendar有一组自己的字段:id,start,end,title.其中start的时间也有格式。

一般都是因为这个原因,导致后台获取数据后,却在日历中显示不出来文字信息。

$.ajax({
type: "post",
url: "getCalendar",
dataType: "json",
data: {
start: startdate
},
success: function (data) {
var events = [];
$.each(data, function (i) {
events.push({
id: data[i].id,
title: data[i].title,
start: data[i].start,
end: data[i].end,
Cal_content: data[i].Cal_content
})
})
callback(events);
}
});

controller:

public ActionResult getCalendar(DateTime start)
{
DateTime etime = start.AddMonths(1).AddDays(-1);
Bll.BSP_RunLog brunlog = new Bll.BSP_RunLog();
var sportslst = brunlog.SelectCal((Guid)Session["UserID"], start, etime);
var lst = new List<Model.calendarevent>();
if (sportslst.Count != 0)
{
for (int i = 0; i < sportslst.Count; i++)
{
lst.Add(new Model.calendarevent
{
id = i + 1,
start = sportslst[i].RunDate.ToString("yyyy-MM-dd") + " 08:30:00",
end = sportslst[i].RunDate.ToString("yyyy-MM-dd") + " 10:30:00",
title = "当日运动量",
Cal_content = "运动量为:" + sportslst[i].RunDistance.Tostring() + "公里"
});
}
}
return Json(lst, JsonRequestBehavior.AllowGet);
}