2015-01-16 2 views
0

내 HTML의 밑줄 템플릿에 백본 컬렉션을 전달하는 데 문제가 있습니다. 지금 템플릿 코드 < % = teamCollection %>은 정의되지 않았습니다. teamCollection은 백본보기에서 템플릿으로 전달하려는 백본 컬렉션입니다. 여기 백본보기가있는 밑줄 템플릿

템플릿 코드 :

<script id="user-home-main-table-template" type="text/template"> 

    <table class="table"> 
    <thead> 
    <tr> 
     <th>#</th> 
     <th>Team Name</th> 
     <th>Club</th> 
     <th>Sport</th> 
     <th>Delete?</th> 
    </tr> 
    </thead> 
    <tbody> 

    <% 
    <!--console.log(<%=teamCollection%>); 
    var teams = <%=teamCollection%>; 
    console.log(teams);--> 

    for(var i=0; i 
    <teams.length 
      ; i++) { %> 
     <!-- <tr onclick=window.document.location='/users/<%=user._id%>/teams/<%= teams[i]._id%>/teamDashboard'>--> 
     <tr> 
      <td> 
       <%=i+1%> 
      </td> 
      <td > 
       <a class="font-big" href='/users/<%=user._id%>/teams/<%= teams[i]._id%>/teamDashboard'> 
        <%= teams[i].teamName %> 
       </a> 
      </td> 
      <td> 
       <a class="font-big" href='/users/<%=user._id%>/teams/<%= teams[i]._id%>/teamDashboard'> 
        <%= teams[i].club %> 
       </a> 
      </td> 
      <td> 
       <a class="font-big" href='/users/<%=user._id%>/teams/<%= teams[i]._id%>/teamDashboard'> 
        <%= teams[i].sport %> 
       </a> 
      </td> 
      <td> 
       <a class="btn btn-warning" onclick=window.userHomeMainTableView.deleteTeam('<%=teams[i]._id%>');>delete</a> 
      </td> 
     </tr> 
     <% } %> 
    </tbody> 
</table> 
</script> 

그리고 여기 백본 코드 :

여기
var Team = Backbone.Model.extend({ 
    idAttribute: "_id", 
    urlRoot: '/api/teams' 
}); 

var TeamCollection = Backbone.Collection.extend({ 
    model: Team 
}); 

var teamCollection = new TeamCollection([]); 

var UserHomeMainTableView = Backbone.View.extend({ 
    tagName: "div", 
    collection: teamCollection, 
    events: {}, 
    initialize: function() { 
     this.render(); 
    }, 
    render: function() { 
     //this.template = _.template($('#tmpl').html()); 
     var userHomeMainTableTemplate = document.getElementById('user-home-main-table-template').innerHTML; 
     var template = _.template(userHomeMainTableTemplate); 
     //this.$el.html(_.template(userHomeMainTableTemplate)()); 
     this.$el.html(template({teamCollection:teamCollection})); 
     console.log('userHomeMainTableTemplate rendered'); 
     return this; 
    }, 
    addTeam: function (teamData) { 
     console.log('adding team:', team_id); 
    } 
}); 

가 JSFiddle이다 나는 분명 하나 작업 얻을 수없는이 질문에 해당 : http://jsfiddle.net/the1mills/26dkh5wa/

+0

템플릿 마크 업에서 템플릿 마크 업이란 무엇을 의미합니까? –

답변

0

teamCollectionteamCollection이 자바 스크립트 코드에서 정의되지 않았기 때문에 템플릿에서 정의되지 않았습니다. 귀하의 코드에서 teamCollection 선언을 찾을 수 없습니다.

+0

감사합니다. 문제가 아닌 예제를 수정했습니다. –