Fullcalendar 不显示 ajax 获取的事件。事件已成功通过,因为我可以通过弹出窗口显示它,但它没有显示在日历中。如果我手动设置事件,完整日历将显示事件,但一旦我使用来自文件的数据传递.cs它就无法呈现。
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web.Services;
using System.Linq;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Collections;
using System.Data;
namespace TravelPlannerO
{
public partial class Schedule : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class Event
{
public string id { get; set; }
public string title { get; set; }
public string start { get; set; }
public string end { get; set; }
public string desc { get; set; }
public string status { get; set; }
public Event(string id, string title, string start, string end,string desc,string status)
{
this.id = id;
this.title = title;
this.start = start;
this.end = end;
this.desc = desc;
this.status = status;
}
};
[WebMethod]
public static string GetEvent()
{
string strSelect;
SqlCommand cmdSelect;
SqlDataReader dtr;
SqlConnection conn;
string connStr = ConfigurationManager.ConnectionStrings["plannerdb"].ConnectionString;
conn = new SqlConnection(connStr);
strSelect = "Select * from [Source.SavedPlan]";
cmdSelect = new SqlCommand(strSelect, conn);
conn.Open();
dtr = cmdSelect.ExecuteReader();
<script src="Scripts/moment.min.js"></script>
<script src="Scripts/jquery-ui.custom.min.js"></script>
<script src="Scripts/fullcalendar.min.js"></script>
<script type="text/javascript">
var listofevent;
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events:function (id,title,start, end, callback) {
$.ajax({
type: "POST ",
url: '<%=Microsoft.AspNet.FriendlyUrls.FriendlyUrl.Resolve(" /Schedule.aspx / GetEvent ")%>',
data: {},
contentType: "application / json;charset = utf - 8 ",
dataType: "json ",
success: function (list) {
listofevent = list.d;
alert(listofevent);
var events = [];
alert(list.d);
var obj = $.parseJSON(list.d);
console.log(obj);
$(list).find('event').each(function () {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end')
});
console.log(obj.calEvent);
});
//callback(events);
callback && callback(events);
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
},
defaultDate: '2015-1-1',
selectable: true,
editable: true,
selectHelper: true,
eventLimit: true, // allow "
more " link when too many events
</script>
<link href="Content/fullcalendar.css" rel="stylesheet" /> <link href="Content/fullcalendar.print.css" rel="stylesheet" media="print" /> <link href="Content/jquery-ui.min.css" rel="stylesheet"/>
<div id='calendar'></div>
List<object> array = new List<object>();
if (dtr.HasRows)
{
var index_id = dtr.GetOrdinal("PlanId");
var index_title = dtr.GetOrdinal("Name");
var index_start = dtr.GetOrdinal("DateFrom");
var index_end = dtr.GetOrdinal("DateTo");
var index_desc = dtr.GetOrdinal("Description");
var index_status = dtr.GetOrdinal("Status");
while (dtr.Read())
{
var id = dtr.GetValue(index_id).ToString();
var title = dtr.GetValue(index_title).ToString();
var datestart = dtr.GetValue(index_start).ToString();
var dateend = dtr.GetValue(index_end).ToString();
var desc = dtr.GetValue(index_desc).ToString();
var status = dtr.GetValue(index_status).ToString();
DateTime RealStartDate = Convert.ToDateTime(datestart);
DateTime RealEndDate = Convert.ToDateTime(dateend);
string start = RealStartDate.ToString("s");
string end = RealEndDate.ToString("s");
Event eventrows = new Event(id, title, start, end,desc,status);
array.Add(eventrows);
}
}
string myJsonString = (new JavaScriptSerializer()).Serialize(array);
return myJsonString;
}
private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
}
}
在我的视觉工作室中,两者之间没有空格 我想当我把它粘贴在这里时,我可能会不小心把它隔开。我不明白为什么事件没有显示。当我从成功打印"list.d"时:函数(列表),结果是[{"id:"1","title":"testoh","start":"2015-01-01T00:00:00","end":"2015-01-02T00:00:00","desc":"abaaba","status":"first "},[{"id:"2","title":"okok","start":"2015-05-01T00:00:00","end":"2015-05-02T00:00:00","desc":"fdgd","status":"second "}]格式是否正确?我注意到我的回调函数没有被调用,但我不知道为什么
我通过编辑events:function (id,title,start, end, callback)
中的参数来解决这个问题,以events:function (start, end,timezone, callback)
. 顺便说一句,感谢您的回复。