Boa noite, Pessoal conseguem me ajudar com o código abaixo, ao fazer o render da minha página que contem um FullCalendar preciso passar um array do tipo JSON para o atributo “events” que está dentro de um trecho que é o inicializador do fullcalendar, sabem uma forma de eu fazer isso utilizando a mesma estrutura do render?
Aqui está o trecho que do render no meu arquivo “agenda.js”:
module.exports = {
pageAgenda: (req, res) => {
//Consulta tabela para popular conteúdo da página
let query = "SELECT * FROM `tb_agenda`";
db.query(query, (err, results, fields) => {
//Passa o conteúdo das variáveis para a página principal
res.render('./pageAdmin', {
DTAgenda: results //Aqui passa o retorno da consulta para a página
});
});
},
}
E aqui está o trecho da minha página font-end que recebe os dados e deveria popular meu FullCalendar:
<div class="card-body">
<!-- Aqui fica meu FullCalendar -->
<div id='calendar'></div>
</div>
<!-- Inicializa o FullCalendar -->
<script>
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'pt-br',
timeZone: 'local',
themeSystem: 'bootstrap',
dayMaxEvents: true, // when too many events in a day, show the popover
contentHeight: 600,
businessHours: false, // display business hours
selectable: true,
expandRows: true,
initialView: 'timeGridWeek',
initialDate: new Date(),
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
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);
}
},
<!-- Aqui está o problema -->
events: [
'<% DTAgenda.forEach((row, index) => { %>'
title: '<%= row.title %>',
description: '<%= row.description %>',
start: '<%- row.start %>',
end: '<%- row.end %>',
'<% }) %>'
]
});
calendar.render();
});
</script>