【发布时间】:2019-11-25 03:45:33
【问题描述】:
我正在为我的作家的休假创建日历。 在这段代码中,它是硬编码的,当然可以工作
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);
}
}
});
现在我编写了这个脚本 (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);
我的问题是如何使用第一个代码上的事件数组将这些结果放入日历中。
我想把结果放在这里,在这个变量中
events : [
{
title : 'All Souls Day',
start : new Date(y, m, 2),
backgroundColor: '#f56954', //red
borderColor : '#f56954' //red
},
],
感谢您的帮助。
【问题讨论】:
-
你能显示你从ajax得到的数据吗
-
您使用的是 FullCalendar,哪个版本?如果您使用,请按照文档进行操作,因为它有很好的演示。
-
@KamleshBhurke 这是结果 [] 0: "{"title":"Buding Leave","start":"2019-11-28","end":"2019-11-28 ","backgroundColor":"#f56954","borderColor":"#f56954"}" 1: "{"title":"Buding Leave","start":"2019-11-29","end": "2019-11-29","backgroundColor":"#f56954","borderColor":"#f56954"}" 长度: 2 proto: Array(0)
标签: jquery arrays ajax fullcalendar fullcalendar-4