Отображение событий в Fullcalendar jquery?

0

используя функцию в "событиях", я не могу отображать свои события, но если я использую строку, сгенерированную в консоли, с помощью console.log той же возвращаемой переменной, я могу отображать мои события. Зачем?

$(document).ready(function () {

                    var date = new Date();
                    var d = date.getDate();
                    var m = date.getMonth();
                    var y = date.getFullYear();

                    // page is now ready, initialize the calendar...
                    var calendar = $('#calendar');
                    calendar.fullCalendar({
                        // put your options and callbacks here
                        'theme': false,
                        'header': {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,agendaWeek,agendaDay'
                        },
                        'weekends': false,
                        'defaultView': 'agendaDay',
                        axisFormat: 'HH:mm',
                        timeFormat: {
                            // for agendaWeek and agendaDay
                            agenda: 'H:mm{ - H:mm}', // 5:00 - 6:30
                            // for all other views
                            '': 'H(:mm)t'            // 7p
                        },
                        minTime: 8,
                        ignoreTimezone: true,
                        editable: true,
                        selectable: true,
                        selectHelper: true,
                        select: function (startDate, endDate, allDay, jsEvent, view) {
                            /*
                             after selection user will be promted for enter title for event.
                             */
                            var title = prompt('Event Title:');
                            /*
                             if title is enterd calendar will add title and event into fullCalendar.
                             */
                            if (title) {
                                calendar.fullCalendar('renderEvent',
                                        {
                                            title: title,
                                            start: startDate,
                                            end: endDate,
                                            allDay: allDay
                                        },
                                        true // make the event "stick"
                                );
                            }
                            calendar.fullCalendar('unselect');
                        },
                        eventDrop: function (event, delta) {
                            alert(event.title + ' was moved ' + delta + ' days\n' +
                                    '(should probably update your database)');
                        },
                        events: function getjson() {

                            var out;

                            $.ajax({
                                url: 'http://localhost:8000/calendar/api/events/events/',
                                type: 'GET',
                                async: false,
                                success: function (data) {
                                    out = JSON.stringify(data['objects']);
                                },
                                error: function () {
                                    alert('errore');
                                }
                            });
                            console.log('hshshshshsh', out);
                            return out;

                        }

Я использую ресурс json, который отображает объекты событий

Теги:
fullcalendar

2 ответа

0

Следующий код работает для меня... он может найти вас полезным. Просто делайте изменения в соответствии с вашим кодом

 events: function (start, end, callback) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Put your url here",
                    dataType: "json", // datatype returned by the webservice

                    success: function (data) {
                        var events = $.map(data.d, function (item, i) {
                            var event = new Object();
                            event.id = item.id;
                            event.start = new Date(item.date);
                            event.title = item.title;
                            event.color = item.color;

                            return event;
                        });
                        callback(events);

                    }, //end of Success function

                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                          alert("StatusEvents: " + textStatus);
                                                 alert("Error: " + errorThrown);
                    }

                }); //end of Ajax Function


            } //end of events function

и моя сущность json похожа

 [Serializable]
public class Events 
{
    public int id { get; set; }
    public string title { get; set; }
    public DateTime date { get; set; }
    public string color { get; set; }
}
  • 0
    он сказал мне код ошибки 400 "плохой запрос" .. может быть, мне нужно использовать запрос GET вместо POST?
  • 0
    нет запроса на публикацию правильно .... Вы передали правильный тип данных, такой как dataType: "json"?
Показать ещё 1 комментарий
0

Вы можете ввести URL-адрес напрямую (как указано здесь):

calendar.fullCalendar({
    events: 'http://localhost:8000/calendar/api/events/events/'
});

Ещё вопросы

Сообщество Overcoder
Наверх
Меню