使用JSON将事件映射到FullCalendar

目前正在处理jquery fullcalendar,我无法从后面的代码中添加事件。

我已经尝试了所有这些可能的解决方案,但它们都没有为我工作:

  • Fullcalendar /获取JSON提要(已编辑)
  • 即使正确的JSON提要,fullCalendar事件也不会显示
  • JQuery FullCalendar不显示来自aspx页面的事件

这是我的代码

[的WebMethod]

public static String TestOnWebService() { int i = 1; string myJsonString = ""; List myList = new List(); dt = db.getPublicHolidays(); foreach (DataRow dr in dt.Rows) { var id = i; var title = dr["name"].ToString(); var start = dr["startDate"].ToString(); var end = dr["endDate"].ToString(); //Convert Implicity typed var to Date Time DateTime RealStartDate = Convert.ToDateTime(start); DateTime RealEndDate = Convert.ToDateTime(end); //Convert Date Time to ISO String SendStartDate = RealStartDate.ToString("s"); String SendEndDate = RealEndDate.ToString("s"); Events t_table = new Events(id, title, start, end); myList.Add(t_table); i++; } myJsonString = (new JavaScriptSerializer()).Serialize(myList); return myJsonString; } } 

和我的活动课

  public class Events { public int id { get; set; } public String title { get; set; } public String start { get; set; } public String end { get; set; } public Events(int id2, String I, String t, String ds) { this.id = id2; this.title = I; this.start = t; this.end = ds; } } 

这是前端代码

 events: function (start, end, callback) { $.ajax({ type: "POST", //WebMethods will not allow GET url: '', //url of a webmethod - example below contentType: "application/json; charset=utf-8", dataType: "json", success: function (doc) { var events = []; //javascript event object created here var obj = $.parseJSON(doc.d); //.net returns json wrapped in "d" for(var i=0;i<obj.length;i++){ console.log(obj[i]['id']); console.log(obj[i]['title']); console.log(obj[i]['start']); console.log(obj[i]['end']); } $(obj.event).each(function () { //yours is obj.calevent events.push({ title: $(this).attr('title'), //your calevent object has identical parameters 'title', 'start', ect, so this will work start: $(this).attr('start'), // will be parsed into DateTime object end: $(this).attr('end'), id: $(this).attr('id') }); }); callback(events); } }); } 

这是我得到的结果

在此处输入图像描述

在三天的挣扎之后,我开始工作了! 我从数据库添加了事件以添加到jquery fullcalender。 这就解决了我的问题! 这是我的代码

我的HTML和JavaScript代码

   

Draggable Events

Create Event


下面是代码隐藏函数,它从db返回json数据

 [WebMethod] public static String TestOnWebService() { int i = 1; string myJsonString = ""; List myList = new List(); dt = db.getPublicHolidays(); foreach (DataRow dr in dt.Rows) { var id = i; var title = dr["name"].ToString(); var start = dr["startDate"].ToString(); var end = dr["endDate"].ToString(); //Convert Implicity typed var to Date Time DateTime RealStartDate = Convert.ToDateTime(start); DateTime RealEndDate = Convert.ToDateTime(end); //Convert Date Time to ISO String SendStartDate = RealStartDate.ToString("s"); String SendEndDate = RealEndDate.ToString("s"); //string start2 = ((RealStartDate.Ticks - 621355968000000000) / 10000000).ToString(); //string end2 = ((RealEndDate.Ticks - 621355968000000000) / 10000000).ToString(); Events t_table = new Events(id, title, SendStartDate, SendEndDate); myList.Add(t_table); i++; } myJsonString = (new JavaScriptSerializer()).Serialize(myList); return myJsonString; } } 

和我的活动课程

 public class Events { public int id { get; set; } public String title { get; set; } public String start { get; set; } public String end { get; set; } public Events(int id2, String I, String t, String ds) { this.id = id2; this.title = I; this.start = t; this.end = ds; } } 

这是输出:D:D

在此处输入图像描述