Jquery fullcalendar 不显示事件

发布于 2024-09-10 13:05:26 字数 2164 浏览 9 评论 0原文

我很高兴看到像 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"}]

你认为哪里出了问题?

I was very excited to see a calendar plugin like fullcalendar. I am trying to use fullcalendar to display events for each month. But the events are not displayed on the calendar.

My code is :

[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);

               });
}

});

And as for my JSON, it looks like:

[{"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"}]

What do you think about what is wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-09-17 13:05:26

这可能与您的财产和价值的报价有关。

尝试在属性和值中都包含引号并检查结果。

我在不使用 JSON.js 的情况下实现了同样的效果。

System.Web.Script.Serialization.JavaScriptSerializer eventListSerializer =
                                                                                    new System.Web.Script.Serialization.JavaScriptSerializer();
                string eventListJSON = eventListSerializer.Serialize(addevList);

This might probably has to do with quotes around your property and values.

Try to include quotes in both property and value and check your result.

I achieved the same without using JSON.js like this.

System.Web.Script.Serialization.JavaScriptSerializer eventListSerializer =
                                                                                    new System.Web.Script.Serialization.JavaScriptSerializer();
                string eventListJSON = eventListSerializer.Serialize(addevList);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文