简体   繁体   English

如何获得fullcalendar.io的正确格式

[英]How to get right format for fullcalendar.io

I have been trying to display my database entries in the calendar. 我一直试图在日历中显示我的数据库条目。 Step 1 is to get data from server in json format. 步骤1是从服务器获取json格式的数据。 step 2: iterate through data to build array. 步骤2:遍历数据以构建数组。 step 3 build array of arrays in accordance to the fullcalendar specs. 第3步根据完整日历规范构建数组数组。

I seem to do great with steps 1 & 2 and if I cut and paste the result as shown it works. 我似乎对步骤1和2做得很好,并且如果按所示方式剪切并粘贴结果,它会起作用。 The diary entries show up where they are supposed to. 日记条目将显示在其应放置的位置。 Woohoo. 呜呼。 However the data will change from day to day as time passes and would like this to work automatically without the cut and pasting. 但是,随着时间的流逝,数据每天都会变化,并且希望此数据能够自动运行而无需剪切和粘贴。

Most of the time I get an indexed array 0:... 1:... 2:... and I think that may be why that does not work. 大多数时候,我会得到一个索引数组0:... 1:... 2:...,我认为这可能就是为什么它不起作用的原因。 When I paste in either a text variable as the data (text) I get nothing and when I push the data into an array, it seems to format ok but still does not show. 当我将任何一个文本变量粘贴为数据(文本)时,我什么也没得到;当我将数据推入数组时,它似乎格式确定,但仍不显示。 Most frustrating. 最令人沮丧。

It turns out the approach I was taking was the correct one. 事实证明,我采用的方法是正确的。 I had however used a variable and called it calendar which threw a spanner in the works. 但是,我使用了一个变量,并将其称为日历,该日历在工作中投入了扳手。 It was a coding problem, but one in the page elsewhere. 这是一个编码问题,但是在其他页面中。

Here's the code I have broken down and where I have got to, which is not elegant as I have taken it to a level of text so that I can cut and paste the text to test - and when I do it works: 这是我分解的代码以及到达的位置,这并不优雅,因为我将它带到了一定水平的文本上,以便可以剪切和粘贴文本进行测试-并且在我可以正常工作时:

 // get appointments
  let events=new Array(); let apptDeat=new Array(); let start; let end; let id; let title=' '; let description=' ';
  $.get('appointmentsList', function(apptList) {
    console.log('apptList1:', apptList, ' Count: ',apptList.Count);
    for (let x=0; x < apptList.Count; ++x) { 
      if (apptList.Items[x].oDdate) {
        start = moment(apptList.Items[x].oDdate).format("YYYY-MM-DD");  start += 'T'+apptList.Items[x].oDtime;
      } else { start =0; }
      if (apptList.Items[x].oDEdate) {
        end   = moment(apptList.Items[x].oDEdate).format("YYYY-MM-DD");    end   += 'T'+apptList.Items[x].oDEtime;
      } else { end =0; }          
      if (apptList.Items[x].oDNumber) { title       = apptList.Items[x].oDNumber; } else { title=' '; }
      if (apptList.Items[x].oDTopic)  { description = apptList.Items[x].oDTopic;  } else { description=' '; }
      id=apptList.Items[x].Id;

      apptDeat +=  '{"title":"'+title+'","description":"'+description+'","id":"'+id+'","start":"'+start+'","end":"'+end+'","color":"blue" },';
    }
    apptDeat = apptDeat.substring(0, apptDeat.length-1);
    events.push(apptDeat);
    console.log('event: ', event, ' events: ', events, ' apptDeat: ', apptDeat);
    let today = new Date();
    let dateInput;
    $('#calendar').fullCalendar({
      eventClick: function(eventObj) { appDetail(eventObj.id); },
      events: events
      //[ {"title":"EVE0106820","description":" ","id":"apptDetails:8171433761442206","start":"2019-02-12T08:30","end":"2019-02-13T05:31" },{"title":"EVE0107006","description":" ","id":"apptDetails:8171581388491175","start":"2019-02-07T08:31","end":"2019-02-08T17:31" },{"title":"EVE0106551","description":"AWS DevOps","id":"apptDetails:8171864774477945","start":"2019-01-28T09:00","end":"2019-01-31T16:00" } ]
    });

By the way, I am using Chrome & the developer tools to see the variables console to the log. 顺便说一句,我正在使用Chrome和开发者工具来查看日志的变量控制台。

This question is unclear on what the specific problem is, but it does seem like some things are off. 这个问题尚不清楚具体的问题是什么,但似乎有些事情已经解决了。

According to the FullCalendar docs , the events property can be multiple things, including an array of objects, which is what it seems like you're trying to pass it. 根据FullCalendar docs说法events属性可以是多种事物,包括对象数组,这就是您试图传递它的方式。 This line of code: 这行代码:

apptDeat +=  '{"title":"'+title+'","description":"'+description+'","id":"'+id+'","start":"'+start+'","end":"'+end+'","color":"blue" },';

seems horrifying. 似乎很恐怖。 If you're trying to build an array of objects to be passed in (which is what their docs say), this is not the way. 如果您要构建要传递的对象数组(这就是他们的文档所说的),则不是这样。 You're building a string of "objects", not an array of objects. 您正在构建字符串“对象”,而不是对象数组。 You keep appending to this string, then you simply push this string into an empty array. 您继续追加到该字符串,然后只需将该字符串推入一个空数组即可。 What you're left with, I'm assuming, is a single array of one messed up string. 我假设您剩下的是一个由一个混乱的字符串组成的数组。

apptDeat should not be an array, it should be an object, and inside your for loop, you should be assigning values to apptDeat as an object and then pushing that to your events array, like so: apptDeat不应为数组,而应为对象,并且在for循环内,应为apptDeat作为对象分配值,然后将其推送到events数组,如下所示:

apptDeat = {
  title,
  description,
  id,
  start,
  end,
  color: "blue"
};

events.push(apptDeat);

Sidenote, yikes @ that code formatting. 旁注,@表示代码格式。 Hopefully that was just StackOverflow messing it up. 希望那只是StackOverflow搞砸了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM