2014-04-22 3 views
0

질문 : fetch() 메서드의 데이터를 HTML로 저장하는 방법은 무엇입니까? 그렇게하려고 할 때 아무런 렌더링이 필요하지 않습니다! 밑줄이있는 테이블에 데이터를 넣는 방법은 무엇입니까?

define([ 
     "underscore", 
     "backbone", 
     "jquery", 
     "pages/RestaurantPage/collections/UsersCollection", 
     "text!pages/RestaurantPage/templates/UsersTable.html" 
    ], 

    function(_, Backbone, $, UsersCollection, UsersTable) { 
     return Backbone.View.extend({ 
      el: $('#data_table'), 
      render: function() { 
       that = this; 
       var users = new UsersCollection; 
       users.fetch({ 
        success: function(users) { 
         var template = _.template($('#data_table').html(), { 
          'users': users.toArray() 
         }); 
        that.$el.html(UsersTable); 
        } 
       }); 
      } 
     }); 
    }); 

내 HTML 파일 :

<table align="center" border="1" cellpadding="1" cellspacing="1" > 


    <caption> 
    All users 
    </caption> 

    <thead> 
    <tr> 

     <th scope="col">Name</th> 

     <th scope="col">Last name</th> 

     <th scope="col">Login</th> 

     <th scope="col">Email</th> 

     <th scope="col">Role</th> 

     <th scope="col">Edit</th> 

     <th scope="col">Delete</th> 

     <th scope="col"> 
     <form id="deleteall" method="post" action="/deleteall" name="deleteall"></form> 

     <div class="small success btn"> 
      <input type="submit" value="X" form="deleteall" /> 
     </div> 
     </th> 

    </tr> 
    </thead> 

    <tbody> 

<% _.each(users, function(user, key, list) { %> 
    <tr> 
     <td><%= key %></td> 

     <td><%- user.get('l_name') %></td> 

     <td><%- user.get('f_name') %></td> 

     <td><%- user.get('email') %></td> 

     <td><%- user.get('id_role') %></td> 
<% }) %> 

     <td> 

    </tr> 
    </tbody> 

</table> 

나는 테이블에 내 컬렉션을 렌더링 할이 ... 내가 무엇을 할 수 있습니까? 왜냐하면 렌더링하려고 할 때 데이터가없는 빈 페이지가 나타납니다.

+0

:

<script type="text/template" id="my_template"> <table align="center" border="1" cellpadding="1" cellspacing="1" > ... </table> </script> 

그런 다음 템플릿 함수 템플릿의 ID를 사용할 수 있습니까? 나는 당신의'table'에 그것을 기대할 것입니다. – Hazaart

+0

"data_table"은 y 인덱스 페이지에있는

요소의 ID입니다. – SemoleX

답변

0

빈 div의 템플릿을 만들고 있습니다. 당신은 같은 당신의 HTML의 템플릿을 만들고 싶어 : 어떤 요소 ID가 "data_table"가

var template = _.template($('#my_template').html(), { 
     'users': users.toArray() 
}); 
관련 문제