The*_*bie 1 arrays ajax jquery fullcalendar fullcalendar-4
我正在创建一个日历以请假。在这段代码中,它是硬编码的,当然可以工作
var calendar = new Calendar(calendarEl, {
plugins: [ 'bootstrap', 'interaction', 'dayGrid', 'timeGrid' ],
header : {
left : 'prev,next today',
center: 'title',
right : 'dayGridMonth,timeGridWeek,timeGridDay'
},
//Random default events
events : [
{
title : 'All Souls Day',
start : new Date(y, m, 2),
backgroundColor: '#f56954', //red
borderColor : '#f56954' //red
},
],
editable : true,
droppable : true, // this allows things to be dropped onto the calendar !!!
drop : function(info) {
// is the "remove after drop" checkbox checked?
if (checkbox.checked) {
// if so, remove the element from the "Draggable Events" list
info.draggedEl.parentNode.removeChild(info.draggedEl);
}
}
});
Run Code Online (Sandbox Code Playgroud)
现在,我编写了此脚本(AJAX)以从数据库中提取记录
var arrevents = [];
$.get( "http://localhost/api/public/events", function( data ) {
var response = JSON.parse(data);
$.each(response, function(k, v) {
arrevents.push(v);
});
});
console.log(arrevents);
Run Code Online (Sandbox Code Playgroud)
我的问题是如何使用第一个代码中的events数组将这些结果放入日历中。
我想将结果放在此变量中
events : [
{
title : 'All Souls Day',
start : new Date(y, m, 2),
backgroundColor: '#f56954', //red
borderColor : '#f56954' //red
},
],
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助。
好的,我认为您使用FullCalendar v4,如果我说对了,那么您需要回调以将事件数据传递到日历。像这样。
根据DOCS,您需要具有successCallback将事件返回到日历的功能。
由于我不知道您的Ajax流程,我只是制作了一个API,该API返回您的数据,然后将其传递给,successCallback从而在完整日历上正确打印事件,
注意:由于活动的日期分别在11/28和11,29,因此请导航至这些日期以查看活动。
演示https://codepen.io/nasser-ali-karimi/pen/qBBGVbG?editors=0010
events: function(info, successCallback, failureCallback) {
var arrevents = [];
jQuery.get( "https://api.myjson.com/bins/16ubhe", function( data ) {
// var response = JSON.parse(data);
// $.each(response, function(k, v) {
// arrevents.push(v);
// });
arrevents = data;
successCallback(arrevents);
});
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45 次 |
| 最近记录: |