2013-11-21 8 views
1

리소스 일보기 (출처 : https://github.com/ikelin/fullcalendar)를 사용하여 FullCalendar 1.5.4에서 배열을 반환하는 데 문제가 있습니다. 여기
내 컨트롤러 :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"} 


내 반응 :

여기
Marie Curie 
Gustave Eiffel 

내 오류 :

[{"id":1,"name":"Marie Curie"},{"id":2,"name":"Gustave Eiffel"}] 

CONSOLE.LOG (listOfResources [I] .name과)의 반환

TypeError: resources[i] is undefined headCell.html(resources[i].name); 
+0

콜백으로 사용되는 기능을 포함 할 수 있습니까? 문제는 게시 한 코드가 아닌 것처럼 보입니다. –

+0

함수 콜백 (배열) {리턴 배열} – Cyril

+0

그리고 지금은 함수 콜백 정의되지 않았습니다 – Cyril

답변

0

코드에서 ListOfResources을 정의하지 않았으므로 callback(ListOfResources);이 작동하지 않습니다.

나는 listOfResources into the 콜백`에 전달하고 싶습니다. 다른 케이스에 유의하십시오.

callback(listOfResources) 
+0

캐스트 오류는 내가 Stackoverflow에 코드를 복사했을 때 이루어졌다 :) 그래서 오류가 거기에서 오지 않습니다 – Cyril

관련 문제