发行加载事件Fullcalendar.io [英] Issue loading events Fullcalendar.io

查看:178
本文介绍了发行加载事件Fullcalendar.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用fullcalendar.io,我们想从我们的api控制器获取一个事件.

We are using fullcalendar.io and we want to get an event from our api controller.

我们的控制人

[Route("api/Bookings")]
public class BookingApiController
{

    // GET
    [HttpGet]
    public string Get()                   
    {

        var returnJson = new
        {
            events = new[]
            {
                new {title = "bro", start = "2018-05-06"},
                new {title = "bro2", start = "2018-05-05"}
            }
        };
        return JsonConvert.SerializeObject(returnJson);

    }
}

我们的javascript文件

Our javascript file

$(function () {

    $('#calendar').fullCalendar({
        //weekends : false

        dayClick: function (date) {

            window.location.href = "/Booking/Booking?selectedDate=" + date.format();
        },

        eventSources: [
            {
                url: '/api/Booking',
                color: 'yellow',    // an option!
                textColor: 'black'  // an option!
            }
        ]

    })
});

但是,javascript脚本永远无法正确获取事件.我们可以看到它接收到JSON,但未将事件正确添加到日历中.

However the the javascript script never gets the event correctly. We can see it receives the JSON but not adding the event correctly to the calendar.

推荐答案

最终返回的JSON是什么样的(如果您在浏览器工具中查看ajax请求,就可以看到它)?

What does the final returned JSON look like (you can see it if you watch your ajax request in the browser tools)?

fullCalendar期望事件的平面排列,但是看起来您正在将它们包装在另一个对象中,因此fullCalendar不会看到它们.只是假设没有事件要返回.

fullCalendar expects a flat array of events, but it looks like you're returning them wrapped up inside another object, so fullCalendar will not see them. It will just assume there were no events to return.

我怀疑您收到的是这样的东西:

I suspect you are receiving something like this:

{
  events: [ 
    //...array of events
  ]
}

您仅需要以下内容:

[
    //...array of events
]

这是未经测试的,但我敢肯定它将解决此问题:

This is untested, but I'm pretty sure it will fix it:

[HttpGet]
public string Get()                   
{
    var events = new[]
    {
        new {title = "bro", start = "2018-05-06"},
        new {title = "bro2", start = "2018-05-05"}
    };

    return JsonConvert.SerializeObject(events);
}

请注意,此版本中不包含外部"returnJson"对象.

Note the absence of the outer "returnJson" object in this version.

请参见 https://fullcalendar.io/docs/events-json-feed有关事件供稿系统(您正在使用的系统)的描述,也可以在此处 https://fullcalendar .io/docs/events-array 作为形成有效事件列表所需的对象格式的示例.

See https://fullcalendar.io/docs/events-json-feed for a description of the event feed system (which you're using) but also here https://fullcalendar.io/docs/events-array for an example of the object format required to form a valid list of events.

这篇关于发行加载事件Fullcalendar.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆