在FullCalendar 1.5.4中返回一个带有资源日视图(来源:https://github.com/ikelin/fullcalendar )的数组有一个问题。
这里我的控制器:
[HttpPost]
public JsonResult GetResources()
{
var data =db.Patients.ToList();
return Json(data.Select(i => new
{
id = i.PatientID,
name = i.FirstName + " " + i.LastName
}),JsonRequestBehavior.AllowGet);
}这里我的观点:
var calendar = $('#calendar').fullCalendar({
defaultView: 'resourceDay',
resources: function (callback) {
$.ajax({
type: "post",
url: '@Url.Action("GetResources", "Patient")',
success: function (d) {
var listOfResources = [];
for (var i = 0, len = d.length; i < len; i++) {
var item = d[i];
listOfResources.push(item);
console.log(listOfResources[i].name);
}
callback(listOfResources);
},
error: function (e) {
debugger;
}
});
}
})这里我的json结果
0 Object { id=1, name="Marie Curie"}
1 Object { id=2, name="Gustave Eiffel"}与我的回应:
[{"id":1,"name":"Marie Curie"},{"id":2,"name":"Gustave Eiffel"}]console.log的返回(listOfResourcesi.name) :
Marie Curie
Gustave Eiffel这里我的错误:
TypeError: resources[i] is undefined
headCell.html(resources[i].name);发布于 2013-11-21 18:29:33
从您的代码中,您没有定义ListOfResources,因此callback(ListOfResources);无法工作。
我相信你想通过listOfResources into the的回调。注意不同的套管:
callback(listOfResources)https://stackoverflow.com/questions/20128759
复制相似问题