Javascript SyntaxError:意外标记非法-下划线模板
我使用主干作为框架来显示所有项目的列表。在呈现下划线模板时,我在运行时遇到一个“underline.js”错误,错误为:Javascript SyntaxError:意外标记非法-下划线模板,javascript,backbone.js,underscore.js,Javascript,Backbone.js,Underscore.js,我使用主干作为框架来显示所有项目的列表。在呈现下划线模板时,我在运行时遇到一个“underline.js”错误,错误为:SyntaxError:Unexpected token非法 以下是我的主要观点: define([ 'jquery', 'underscore', 'backbone', 'collections/projects', ], function($, _, Backbone, ProjectsCollection){ v
SyntaxError:Unexpected token非法
以下是我的主要观点:
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=559;.template($('#userList').html(),{projectlist:projectlist.models})
步骤中,它中断并运行到underline.js文件中的ilegal标记错误中。我想知道可能是什么错误。有什么想法吗???我在jsbin中查看了它,似乎在您结束之前有一个不可见的字符。请尝试删除该空白行,看看是否有效。我尝试删除“”和“”之间的空白行。我很想知道你是怎么用jsbin的。你能发送链接吗?感谢您是否可以使用user.get()
删除所有行,然后逐个添加回去,以检查导致问题的特定属性?另外,我可能弄错了,但不应该self.$el.html(模板)
beself.$el.html(模板())
?哦,是的,我一个接一个地尝试了,它神奇地工作了..不确定是什么原因..我猜可能是一些空格导致了错误..谢谢你的建议。