我想在ASP.net中的Jquery日历控件中显示报表,因为我需要从Database中检索数据。我写了这样的服务
[WebMethod]
public static string GetData()
{
Horticulture h = new Horticulture();
return h.GetProjectedYield().GetXml();
}
这里我将数据集转换为xml,然后我在javascript中调用该函数,如下所示
$(document).ready(function () {
var response;
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: 'ProjectedYieldCalender.aspx/GetData',
data: '{}',
success:
function (res) {
var xmlDoc = $.parseXML(res.d);
var xml = $(xmlDoc);
var customers = xml.find("Table1");
}
});
然后我需要将重试数据绑定到JQuery Calender控件,如下所示
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
//defaultDate: '2014-08-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
for(var i=0; i<customers.length; i++)
{
"{"
"title:" +customers[i].Column1+","
"start:"+customers[i].Column3
"}"
if(i!=customers.length-1)
{
","
}
}
]
});
});
但我没有得到正确的输出(无法找到),但我需要按如下方式生成
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultDate: '2014-11-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2014-11-01'
},
{
title: 'Long Event',
start: '2014-11-07',
end: '2014-11-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-11-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2014-11-16T16:00:00'
},
{
title: 'Conference',
start: '2014-11-11',
end: '2014-11-13'
},
{
title: 'Meeting',
start: '2014-11-12T10:30:00',
end: '2014-11-12T12:30:00'
},
{
title: 'Lunch',
start: '2014-11-12T12:00:00'
},
{
title: 'Meeting',
start: '2014-11-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2014-11-12T17:30:00'
}
]
});
});
任何人都可以让我知道怎么做吗?我哪里错了?
答案 0 :(得分:1)
简单化 - 不要在Web服务中返回XML,返回事件对象列表。
public class CEvent
{
public int id {get;set;}
public string title {get;set;}
public DateTime start {get;set;}
}
[WebMethod]
public List<CEvent> GetData()
{
return new List<CEvent>{...};
}
$(document).ready(function () {
var response;
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: 'ProjectedYieldCalender.aspx/GetData',
data: '{}',
success:
function (data) {
var eventList = data;
// OR var eventList = data.d
initCalendar(eventList);
}
});
function initCalendar(eventList){
$('#calendar').fullCalendar({
defaultDate: '2014-11-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: eventList
});
}