Html 是什么导致 SyntaxError:下划线模板中出现意外的 EOF 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16234204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is causing SyntaxError: Unexpected EOF error in underscore template?
提问by SamBrick
I am getting a SyntaxError: Unexpected EOF output when using an underscore template to render html in a Backbone application. Here is my template:-
使用下划线模板在 Backbone 应用程序中呈现 html 时,出现 SyntaxError: Unexpected EOF 输出。这是我的模板:-
<script type="text/template" id="shellmenu-template">
<div>
<p>menu template html will go here....</p>
<div class="menuButtonsContainer">
<% _.each(menu, function(menuItem){ %>
<button class="menuButton" id="<%= _.escape(menuItem.id)"><%= _.escape(menuItem.title) %></button>
<% }); %>
</div>
</div>
</script>
It is specifically erroring on this part:-
这部分特别错误:-
id="<%= _.escape(menuItem.id)"
The id attribute is a number, here is the menuItem object:-
id 属性是一个数字,这里是 menuItem 对象:-
dataPath: ""
helpType: "default"
id: 0
moduleName: "TestModule"
modulePath: "interaction/test/testmodule"
title: "Test Module Interaction"
I have tried making the id a string or making it the title attribute in the underscore template code just to see if I can get a test case working in any shape or form but I am stumped so far. I have a similar template doing pretty much the same thing with no errors.
我曾尝试将 id 设为字符串或将其设为下划线模板代码中的 title 属性,只是为了看看我是否可以让测试用例以任何形状或形式工作,但到目前为止我都被难住了。我有一个类似的模板做几乎相同的事情,没有错误。
Any ideas what silliness I am engaging in to cause this? :-)
任何想法我正在从事什么愚蠢的事情?:-)
回答by neo
Looks like you didn't close <%=
with %>
看起来你没有关闭<%=
与%>