我的问题是我调用了一个 api,它给了我一组我需要通过 javascript 绑定的 json 数据。我正在使用 fullcalendar API 来显示日历。下面我只是粘贴我的代码,请帮助我。在控制台中我没有任何错误,但仍然无法正常工作。
我正在为我的 api 使用 asp.net mvc 5 并获取我直接使用 javascript js6 fetch 的请求。
我的 JavaScript 代码
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
//fetch data for events
var eventdata = fetch('@Url.Action("GetTsdates", "Remo")')
.then(function (responce) {
responce.json().then(function (data) {
console.log(data);
return data;
})
})
.catch(function (err) {
console.log('Fetch Error :-S', err);
});
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid'],
//defaultDate: '2019-06-12',
editable: true,
eventLimit: true,
events: eventdata
});
calendar.render();
});
控制台中的json数据
{start: "2019-06-01", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-02", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-03", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-04", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-05", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-06", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-07", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-08", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-09", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-10", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-11", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-12", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-13", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-14", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-15", overlap: false, rendering: "background", color: "#f44242"},
{start: "2019-06-16", overlap: false, rendering: "background", color: "#f44242"}
我在控制台中没有任何错误。但它仍然无法正常工作。提前致谢。