我使用骨干作为框架来显示所有项目的列表。虽然渲染下划线模板我遇到'Underscore.js'错误说:SyntaxError: Unexpected token ILLEGAL
以下是我的Backbone View:
define([
'jquery',
'underscore',
'backbone',
'collections/projects',
], function($, _, Backbone, ProjectsCollection){
var ProjectListView = Backbone.View.extend({
el: $(".content"),
render: function(){
var self = this;
var projectlist = new ProjectsCollection();
projectlist.fetch({
success: function(projectlist){
var template = _.template($('#userList').html(), {projectlist:projectlist.models})
self.$el.html(template)
}
})
}
});
return ProjectListView;
});
以下是我用于渲染详细信息的下划线模板:
下划线
<script type = "text/template" id = "userList">
<table>
<thead>
<tr>
<th>name</th>
<th>title</th>
<th>background</th>
</tr>
</thead>
<tbody>
<% _.each(projectlist, function(user){ %>
<tr>
<td><%= user.get('name') %></td>
<td><%= user.get('title') %></td>
<td><%= user.get('background') %></td>
</tr>
<% }) %>
</tbody>
</table>
</script>
HTML作为显示内容的容器:
<div id="container">
<h1>User list</h1>
<div id="menu">Welcome to the project</div>
<div class="content"></div>
</div>
我尝试调试以查看错误可能来自何处,在var template = _.template($('#userList').html(), {projectlist:projectlist.models})
步骤它会中断并运行到underscore.js文件中的ilegal token错误。我想知道错误是什么。请任何ideass ????