backbone.js - How to put data in table with Underscore? -
i have question - how put data method fetch() html? cause when try that, nothing rendering!
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() { = this; var users = new userscollection; users.fetch({ success: function(users) { var template = _.template($('#data_table').html(), { 'users': users.toarray() }); that.$el.html(userstable); } }); } }); });
and html file:
<table align="center" border="1" cellpadding="1" cellspacing="1" > <caption> 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>
i want render collection in table...what can do? cause when try render it, i`m getting blank page no data.
you making template of empty div. want make template of html such:
<script type="text/template" id="my_template"> <table align="center" border="1" cellpadding="1" cellspacing="1" > ... </table> </script>
then in template function use id of template:
var template = _.template($('#my_template').html(), { 'users': users.toarray() });
Comments
Post a Comment