简体   繁体   English

完整日历 - 为事件对象添加额外属性

[英]full calendar - add extra attribute to event object

Probably due to my lack of understanding, but I am bringing back the event data using PHP returning a JSON string. 可能是由于我缺乏理解,但我使用PHP返回一个JSON字符串来恢复事件数据。

<?php

  $json = array();

  // Query that retrieves events
  $requete = "SELECT * FROM DoctorAvailability ORDER BY id";

   try {
        $bdd = new PDO("mysql:host=$servername;dbname=$dbname",$username,$password);
      } catch(Exception $e) {
        exit('Unable to connect to database.');
      }
     // Execute the query
    $resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));

    echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
 ?>

Within the database there are six fields. 在数据库中有六个字段。

Id, title, start, end, backgroundColor, name.

I was wanting to bring back the name although say for instance within eventClick i try 我想把这个名字带回去,虽然比如在eventClick中我试试

 eventClick: function (calEvent, jsEvent, view) {
           calEvent.name;

it doesn't exist. 它不存在。

I know there is something missing from my understanding, but I've spent ages Googling to no avail. 我知道我的理解中缺少一些东西,但我花了很多年时间用谷歌搜索无济于事。

You might look at using eventRender which allows you to access non-standard fields that are added. 您可以查看使用eventRender ,它允许您访问添加的非标准字段。

eventRender: function(event, element) {
    console.log(event.name);
}

From the docs : 来自文档

In addition to the fields above, you may also include your own non-standard fields in each Event Object. 除上述字段外,您还可以在每个事件对象中包含您自己的非标准字段。 FullCalendar will not modify or delete these fields. FullCalendar不会修改或删除这些字段。 For example, developers often include a description field for use in callbacks such as eventRender. 例如,开发人员通常包含用于回调的描述字段,例如eventRender。

Update: 更新:

This is what I use to construct the data for my events: 这是我用来为我的事件构建数据的方法:

// construct the array
foreach ($events as $e) {
    $eventList[] = array(
        'id' => 'event-' . $e->id, // unique identifier for aligning editing window 
        'allDay' => false, // makes the times show
        'title' => $e->fullname, // shows the user's name
        'start' => $e->start_time, // their start time (start working)
        'end' => $e->end_time, // their end time (done working)
        'notes' => $e->notes ? $e->notes : '', // notes, if applicable
        'className' => 'event-' . $e->id,
        'user' => $e->user
    );
};

// echo the data, json encoded for the calendar
echo json_encode($eventList);

Then I access specific data as mentioned above, using eventRender . 然后我使用eventRender访问上面提到的特定数据。

eventRender: function(event, element) {
    element.qtip({
        content: event.notes, // This is a non-standard, custom attribute!
        position: {
            my: 'top left',
            at: 'bottom left'
        }
    });
},

FullCalendar Version 4: Any custom values will be found in ' extendedProps ' of the Event Object FullCalendar版本4:任何自定义值都可以在事件对象的extendedProps ”中找到

events: [

                    {
                    title: 'My Title',
                    My_Custom_Value: 'non-standard Event Object field',
                    allDay: false,
                    start: 1501056000000,
                    end: 1501057800000
                    }
],

eventRender: function(info){

                    console.log("_______ info _______\n");
                    console.log(info.event.extendedProps.My_Custom_Value);
}

" extendedProps extendedProps
A plain object holding miscellaneous other properties specified during parsing. 包含解析期间指定的其他其他属性的普通对象。 Receives properties in the explicitly given extendedProps hash as well as other non-standard properties." 接收显式给定的extendedProps哈希以及其他非标准属性中的属性。“

https://fullcalendar.io/docs/event-object https://fullcalendar.io/docs/event-object

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

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