2014-07-24 2 views
0

showallinstructors.cshtml 안에 다음 코드를 작성했습니다. 내 jQuery 템플릿이 작동하지 않습니다.

<h2>Instructors List</h2> 
<table border="1"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Hire Date</th> 
      <th>Twitter</th> 
      <th>Technologies</th> 
     </tr> 
    </thead> 
    <tbody id="instructorsList"> 
     @*Insert instructors here*@ 
    </tbody> 
</table> 

와 제 _Layout.cshtml 파일 I 출력 jQuery를 템플릿을 이용하여 표 형식으로 나타낸 것으로 기대

<head> 
//I have omitted the default Render code 
<script type="text/javascript"> 

var instructors = [ 
    { FirstName: "Matt", HireDate: new Date(2005, 6, 1), Twitter: "milnertweet", FavoriteTech: [{ Name: "jQuery" }, { Name: "WF" }, { Name: "BizTalk" }] }, 
    { FirstName: "Fritz", HireDate: new Date(2004, 8, 1), Twitter: "fritzonion", FavoriteTech: [{ Name: "ASP.NET" }, { Name: "JavaScript" }, { Name: "CSS" }] }, 
    { FirstName: "Aaron", HireDate: new Date(2004, 8, 1), Twitter: "skonnard" } 
]; 

$(function() { 
    $("#instructorTemplate").tmpl(instructors).append("#instructorsList"); 
}); 
</script> 

<script id="instructorTemplate" type="text/x-jquery-tmpl"> 
    <tr> 
     <td>${FirstName}</td> 
     <td>${HireDate}</td> 
     <td>${Twitter}</td> 
     <td>${Technologies}</td> 
    </tr> 
</script> 
</head> 

내부 다음 코드.

나는 단지 테이블 표제뿐입니다.

따라서보기 소스를 확인했습니다. 그러나 문제가있는 곳을 이해할 수 없었습니다.

아무도 내가 실수를하고있는 곳을 제안 할 수 있습니까? 내 stackoverflow 제외하고 제안 할 사람이 없어.

편집 : 코드를 디버깅 할 때 모든 강사가 "강사"변수에 들어감을 발견했습니다. 하지만, 그냥 채우지 않습니다. 나는 그것을하는 방법에 대한 단서가 없습니다.

+0

사용중인 플러그인은 무엇입니까? tmpl? – Lakshay

+0

예. 나는 템플릿을 사용하고있다. –

+0

이유를 말하지 않고 아래로 투표 해 주셔서 감사합니다. 어쨌든, 일부 시도 후에, 나는 해결책을주었습니다. –

답변

2

아주 작은 실수.

위의 코드는해야한다 : 나는 appendTo와을 추가 를 교체 한

$(function() { 
    $("#instructorTemplate").tmpl(instructors).appendTo("#instructorsList"); 
}); 

. 그게 전부 야.

관련 문제