Uncaught SyntaxError: Unexpected token ')' in underscore on looping pattern
I have a problem using underscore in my Backbone app. In my console
Uncaught SyntaxError: Unexpected token ')'
And it refers me to the underline library:
underscore.js: line 1443
What I want to do is select a template by id
var UserList = Backbone.View.extend({
el: '.page',
render: function(){
var self = this;
var users = new Users();
users.fetch({
success:function(users){
console.log(users);
var template = _.template($('#user_list_template').html(), users);
self.$el.html(template);
}
});
}
});
Here is my script template
<script type="text/template" id="user_list_template">
<table class="table striped">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<% _.each(users,function(user)){ %>
<tr>
<td><%= user.name %></td>
<td><%= user.age %></td>
</tr>
<% }); %>
</tbody>
</table>
</script>
And as I found the problem is on this line:
var template = _.template($('#user_list_template').html(), users);
Could you please help me to figure out what is the problem?
+3
source to share