admin管理员组文章数量:1333170
I have a problem when using underscore in Backbone application. In console I have
Uncaught SyntaxError: Unexpected token ')'
And it referer me to the underscore library :
underscore.js:line 1443
What I whant to do is select 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 in this line:
var template = _.template($('#user_list_template').html(), users);
Could you help me please to find what is the problem?
I have a problem when using underscore in Backbone application. In console I have
Uncaught SyntaxError: Unexpected token ')'
And it referer me to the underscore library :
underscore.js:line 1443
What I whant to do is select 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 in this line:
var template = _.template($('#user_list_template').html(), users);
Could you help me please to find what is the problem?
Share Improve this question asked Apr 29, 2015 at 10:20 volodymyr3131volodymyr3131 3452 gold badges6 silver badges16 bronze badges 1- Probably a duplicate of stackoverflow./questions/25881041/… – nikoshr Commented Apr 29, 2015 at 10:24
1 Answer
Reset to default 8<% _.each(users,function(user)){ %>
this line has an extra )
before the {
in your template.
本文标签:
版权声明:本文标题:javascript - Uncaught SyntaxError: Unexpected token ')' in underscore when looping throught template - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742348790a2458065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论