Jquery fullcalendar不显示事件
Posted
技术标签:
【中文标题】Jquery fullcalendar不显示事件【英文标题】:Jquery fullcalendar not showing events 【发布时间】:2010-07-21 22:13:42 【问题描述】:我很高兴看到像 fullcalendar 这样的日历插件。我正在尝试使用 fullcalendar 来显示每个月的事件。但事件不会显示在日历上。
我的代码是:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult HighlightCalendar()
var tasksList = new List<HighlightMonthlyEvents>();
tasksList.Add(new HighlightMonthlyEvents
id = 1,
EventName = "Google search",
EventStartDate = ToUnixTimespan(DateTime.Now),
EventEndDate = ToUnixTimespan(DateTime.Now.AddHours(4)),
url = "www.google.com"
);
tasksList.Add(new HighlightMonthlyEvents
id = 1,
EventName = "Bing search",
EventStartDate = ToUnixTimespan(DateTime.Now.AddDays(1)),
EventEndDate = ToUnixTimespan(DateTime.Now.AddDays(1).AddHours(4)),
url = "www.bing.com"
);
var highlightDays = Jayrock.Json.Conversion.JsonConvert.ExportToString(tasksList.ToArray());
return Json(highlightDays, JsonRequestBehavior.AllowGet);
<script type="text/javascript">
$(function ()
// FullCalendar
$('.fullcalendar').fullCalendar(
theme: true,
header:
left: 'today prev,next',
center: '',
right: ''
,
defaultView: 'month',
editable: false,
events: function (callback)
// do some asynchronous ajax
contentType: "application/json; charset=utf-8",
$.getJSON("/Test/HighlightCalendar/", null,
function (result)
var calevents = new Array();
var results = eval(result);
eval(results.length);
if (results != null)
for (i in results)
var calEvent = results[i];
calevents.push(calEvent)
alert(calevents.length);
// then, pass the CalEvent array to the callback
callback(calevents);
);
);
至于我的 JSON,它看起来像:
["id":1,"allDay":false,"title":"Google search","start":1279750267,"end":1279764667,"url":"www.google.com","id":2,"allDay":false,"title":"Bing search","start":1279836667,"end":1279851067,"url":"www.bing.com"]
你觉得哪里出了问题?
【问题讨论】:
【参考方案1】:这可能与您的属性和值周围的引号有关。
尝试在属性和值中包含引号并检查结果。
我没有像这样使用 JSON.js 也达到了同样的效果。
System.Web.Script.Serialization.JavaScriptSerializer eventListSerializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
string eventListJSON = eventListSerializer.Serialize(addevList);
【讨论】:
以上是关于Jquery fullcalendar不显示事件的主要内容,如果未能解决你的问题,请参考以下文章
无法访问嵌套事件对象的属性 - Fullcalendar jquery插件