none
fullcalendar.io RRS feed

  • Soru

  • ello i am trying to pull events from database. After entering the function, when I want to show the events on the calendar (I can bring the data to the console in the events.push({}) event), no data is coming. where am i doing wrong. can you help me?

    javascript code: 

                    function getByMeetings() {
                        debugger;
                        $.ajax({
                            type: 'GET',
                            url: '@Url.Action("GetMeetingList", "Meeting", new {area="admin" })',
                            success: function (response) {
                                debugger;
                                events = [];
                                var sources = calendar.getEventSources();
        
                                for (var i = 0; i < sources.length; i++) {
                                    sources[i].remove();
                                }
                                for (var i = 0; i < response.length; i++) {
                                    console.log(response[i]);
                                    events.push({
                                        id: response[i].Id,
                                        title: response[i].Title,
                                        requesting: response[i].Requesting,
                                        organizer: response[i].Organizer,
                                        start: moment(response[i].StartDate).format('DD/MM/YYYY HH:mm'),
                                        end: moment(response[i].EndDate).format('DD/MM/YYYY HH:mm'),
                                        description: response[i].Description,
                                        linkUrl: response[i].LinkUrl,
                                        meetingCategoryId: response[i].MeetingCategoryId
                                    });
                                }
                                calendar.addEventSource(events);
                                debugger;
                            },
                            error: function () {
                                $('#saveModal').modal('hide');
                                toastr.error('bir sorun ile karşılaşıldı toplantılar şu an için takvime getirilemiyor.');
                            }
                        });
                    }

    MVC code:

          public JsonResult GetMeetingList()
            {
                var model = _db.GetDefaultRepo<Meeting>()
                  .GetAll()
                  .Select(s =>
                  new MeetingItemViewModel
                  {
                      Id = s.Id,
                      Title = s.Title,
                      Description = s.Description,
                      Requesting = s.Requesting,
                      Organizer = s.Organizer,
                      StartDate = s.StartDate,
                      EndDate = s.EndDate,
                      LinkUrl = s.LinkUrl,
                      MeetingCategoryId = s.MeetingCategoryId
                  }).AsEnumerable();
    
                return Json(model, JsonRequestBehavior.AllowGet);
                //return Json(model);
            }

    26 Kasım 2021 Cuma 09:24

Tüm Yanıtlar

  • you don't need populate data with any loop like "for". You can directly bind json data to events array.
    Ex:

     . 
     .
     success: function (response) {
        events = response;
        var sources = calendar.getEventSources();
     .
     .
        
    Note: it works if response json compatible with fullcalendars event item, so you should change your server side object MeetingItemViewModel. you can make string all properties


    e-mail: onay[nokta]yalciner[at]hotmail[nokta]com




    26 Kasım 2021 Cuma 09:38
  • Since there are different fields than the fullcalende options, I was trying to show the data to the calendar by returning with for.
    26 Kasım 2021 Cuma 10:30
  • ne farkeder ki, gerekli olan alanları modele string olarak koyun, o kendi kullanıcaklarını alır içinden, fazla alan olması fullcalendarı etkilemez.

    json kullanmamızın nedeni zaten js de direk kullanılabilen bişeydir. ayrıca for 5-10 ms olsada calendar çizildikten sonra eventleri doldurur. bu da eventlerin görünmemesine neden olur.


    e-mail: onay[nokta]yalciner[at]hotmail[nokta]com

    26 Kasım 2021 Cuma 10:47
  • işin gücün rast gitsin.
    26 Kasım 2021 Cuma 13:02