Fullcalendar未显示ajax提取的事件。事件成功通过,因为我可以通过弹出显示它,但它没有显示在日历中。如果我手动设置事件,fullcalendar将显示事件,但是一旦我使用.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>
&#13;
<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"/>
&#13;
<div id='calendar'></div>
&#13;
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);
}
}
}
答案 0 :(得分:0)
在我的视觉工作室中,我之间没有任何空间,我想在将其粘贴到此处时可能会意外地将其放置。我不明白为什么事件没有显示。我打印&#39; list.d&#39;从成功:功能(列表),结果是 [{&#34; ID:&#34; 1&#34;&#34;标题&#34;:&#34; testoh&#34;&#34;开始&#34;:&#34; 2015 - 01-01T00:00:00&#34;&#34;端&#34;:&#34; 2015-01-02T00:00:00&#34;&#34;降序&#34;:&#34; abaaba&#34;,&#34; status&#34;:&#34; first&#34;}, [{&#34; ID:&#34; 2&#34;&#34;标题&#34;:&#34;奥科克&#34;&#34;开始&#34;:&#34; 2015 - 05-01T00:00:00&#34;&#34;端&#34;:&#34; 2015-05-02T00:00:00&#34;&#34;降序&#34;:&#34; fdgd&#34;,&#34; status&#34;:&#34; second&#34;}] 格式是否正确?我注意到我的回调函数没有调用,但我不知道为什么
答案 1 :(得分:0)
I solved this by editing the argument in the events:function (id,title,start, end, callback)
to events:function (start, end,timezone, callback)
. btw thanks for the reply..