Fullcalender - 我们可以为我们的活动Json Data添加自定义数据吗?

时间:2022-05-14 20:55:48

I want to send a type in my Event Json Response.

我想在我的Event Json Response中发送一个类型。

Here is my code :

这是我的代码:

$('#calendar').fullCalendar({

eventSources: [ 

{"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
{"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}

]

});

You see I send a type in JSON Response array, is this possible ? What parameter can we use for sending our custom data ?

你看我在JSON Response数组中发送一个类型,这可能吗?我们可以使用什么参数来发送自定义数据?

3 个解决方案

#1


9  

Try It with events: instead of eventSources:

尝试使用事件:而不是eventSources:

$('#calendar').fullCalendar({

 events: [ 

{"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
{"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}

]

});

#2


12  

As per the documentation:

根据文件:

Non-standard Fields

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. For example, developers often include a description field for use in callbacks such as eventRender.

除上述字段外,您还可以在每个事件对象中包含您自己的非标准字段。 FullCalendar不会修改或删除这些字段。例如,开发人员通常包含用于回调的描述字段,例如eventRender。

Example:

例:

$('#calendar').fullCalendar({
    events: [
        {
            title: 'My Event',
            start: '2010-01-01',
            type: 1 // Custom field
        }
    ],
    eventRender: function(event, element) {
        console.log(event.type); // Writes "1"
    }
});

#3


0  

You can also pass url endpoint to events as long as the url returns json response

只要url返回json响应,您也可以将url端点传递给事件

            cId.fullCalendar({
             header: {
                right: '',
                center: 'prev, title, next',
                left: ''
             },

            theme: true, //Do not remove this as it ruin the design
            selectable: true,
            selectHelper: true,
            editable: true,
             //it will load data from this url
            events: "{{ url('api/events') }}",
//               events: getData(),

            //Add Events
        });

and in your controller or function

并在您的控制器或功能

  $events = $request->user()->events()->select('title','color','date')->get();

   //        dd($even,$events)
          $eventsResponse = [];
 //        created_at->format('Y-m-d')
          foreach ($events as $event)
          {
           $eventsResponse[] = [
            'title'=>$event->title,
            'color'=>$event->color,
            'start'=> Carbon::parse($event->date)->toDateTimeString(),
           ];
        }

       return $eventsResponse;

#1


9  

Try It with events: instead of eventSources:

尝试使用事件:而不是eventSources:

$('#calendar').fullCalendar({

 events: [ 

{"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
{"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}

]

});

#2


12  

As per the documentation:

根据文件:

Non-standard Fields

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. For example, developers often include a description field for use in callbacks such as eventRender.

除上述字段外,您还可以在每个事件对象中包含您自己的非标准字段。 FullCalendar不会修改或删除这些字段。例如,开发人员通常包含用于回调的描述字段,例如eventRender。

Example:

例:

$('#calendar').fullCalendar({
    events: [
        {
            title: 'My Event',
            start: '2010-01-01',
            type: 1 // Custom field
        }
    ],
    eventRender: function(event, element) {
        console.log(event.type); // Writes "1"
    }
});

#3


0  

You can also pass url endpoint to events as long as the url returns json response

只要url返回json响应,您也可以将url端点传递给事件

            cId.fullCalendar({
             header: {
                right: '',
                center: 'prev, title, next',
                left: ''
             },

            theme: true, //Do not remove this as it ruin the design
            selectable: true,
            selectHelper: true,
            editable: true,
             //it will load data from this url
            events: "{{ url('api/events') }}",
//               events: getData(),

            //Add Events
        });

and in your controller or function

并在您的控制器或功能

  $events = $request->user()->events()->select('title','color','date')->get();

   //        dd($even,$events)
          $eventsResponse = [];
 //        created_at->format('Y-m-d')
          foreach ($events as $event)
          {
           $eventsResponse[] = [
            'title'=>$event->title,
            'color'=>$event->color,
            'start'=> Carbon::parse($event->date)->toDateTimeString(),
           ];
        }

       return $eventsResponse;