【发布时间】:2020-12-08 08:49:50
【问题描述】:
我正在尝试制作动态日历事件。当日期/月份发生变化时,它会调用控制器函数。我的控制器过滤来自 ajax 调用(开始,结束)的值。所以这些是我的功能
events: function (start, end, callback) {
$.ajax({
type: "POST",
url: "/Home/GetData",
dataType: 'json',
//this automaticly adds Start and End param to controller. Datetime
data: {
},
error: function (xhr, type, exception) { alert("Error: " + exception); },
success: function (response) {
console.log(response);
//Response works fine, it return all objects what I need.
}
});
},
所以基本上这个函数调用GetData json form Home控制器,每个月都有开始和结束参数的变化。我也可以记录它来的这些数据。但是这个事件没有被填满。控制台日志中写着eventrender
eventRender: function (event, element) {
console.log("event");
console.log(event);
--
event
undefined
它不会填充事件,但我也在其他页面中以相同的方式使用它,但它可以工作。
events: {
type: "POST",
url: "/home/GetEvents",
data: function () { // a function that returns an object
return {
};
}
},
我只需要添加它来填充事件。谢谢
我还添加了 evetnSoucers,但它是一样的
eventSources: [
{
url: "/Home/GetData",
method: 'POST',
failure: function () {
alert('there was an error while fetching events!');
}, success: function (response) {
console.log(response);
myfunc(response);
}
}
],
新2
下面的这段代码使用 start、end 参数调用控制器并返回预期值。我可以调用另一个具有响应值的函数,也可以 console.log 这个响应值。当我添加回调来设置我的事件时,它说回调不是函数
events: {
type: "POST",
url: "/home/GetData",
data: function (start, end, timezone, callback) { // a function that returns an object
return {
// dynamic_value: Math.random()
};
}, success: function (response) {
callback(response);
console.log("response");
console.log(response);
some_func(response);
}
},
【问题讨论】:
-
谁能帮我解决这个问题
-
几天前你有这个工作(stackoverflow.com/questions/65106933/…)......有什么变化?你为什么搞砸了?
-
无论如何,请参见 fullcalendar.io/docs/v3/events-function - 它是
function( start, end, timezone, callback ) { }而不是function( start, end, callback ) { }并且您还需要实际使用callback将事件返回到 fullcalendar - 例如success: function (response) { callback(response); }。文档描述并展示了它的使用。 -
是的,正如我所提到的,它适用于您的答案。我以同样的方式在 4 页中使用这个完整的日历。 4 个中的 3 个可以正常工作,但其中一个只是没有显示事件。我可以在每个月的更改中获取开始结束值。我成功添加了 calback(response) 方法。控制台说回调不是函数
-
您还需要进行我描述的其他更改。再次阅读我的评论
标签: jquery json ajax fullcalendar fullcalendar-3