jquery - 在日历引导数组中推送数组
问题描述
我正在为我的作家的休假创建一个日历。在这段代码中,它是硬编码的,当然可以工作
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
},
],
谢谢您的帮助。
解决方案
好的,我认为您使用的是 FullCalendar v4,如果我是对的,那么您需要有一个回调来将您的事件数据传递给日历。像这样。
根据 DOCS,您需要successCallback
将事件返回到日历中。
由于我不知道您的 ajax 流程,我只是制作了一个 API 来返回您的数据,然后将其传递给successCallback
在完整日历上正确打印事件的 API,
注意:由于您的活动日期是 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);
});
},
推荐阅读
- c# - 如何选择具有最低属性 linq 查询语法的对象
- java - Im looking to filter my query to get all names with the relation of ID
- python - 带偏移的鼠标位置
- reactjs - How to connect a native React App to a Rest API using fetch when the Rest API url is http://localhost:8080/
- java - 连接4 java win校验
- java - ScanCallback is Never Executed in Android Bluetooth Low Energy (BLE) Device Scanning App
- php - PHP。无法读取后缀为零的密钥
- matlab - 使用 f2matlab 将 Fortran 代码转换为 MATLAB
- python - 循环遍历一列需要永远
- python - Django 打印用户列表