模板中的_下划线循环
我一直收到这个错误。我不断收到语法错误:
语法错误 var _p=[],print=function(){_p.push.a... ');}return __p.join('');
<script id="product" type="text/template">
<p><span>items</span><span class='items'><%= _.each(info.items, function(books) { %>
<%= books.name + ", " %>
<% }); %></span></p>
</script>
任何人都知道为什么会发生这个错误。我看过其他一些人使用这种风格,它似乎是正确的,但也许我错过了一个符号?
注意:已修复问题。 我的代码在错误的位置有一个 =
符号。
<%= _.each(info.items, function(books) { %>
应该是:
<% _.each(info.items, function(books) { %>
不确定为什么某些区域需要 =
而其他区域则不需要。也许有人可以解释一下。 在代码的这个区域中,我需要使用 =
符号:
<%= books.name + ", " %>
I keep getting an error with this. I keep getting a syntax error:
syntax error var _p=[],print=function(){_p.push.a... ');}return
__p.join('');
<script id="product" type="text/template">
<p><span>items</span><span class='items'><%= _.each(info.items, function(books) { %>
<%= books.name + ", " %>
<% }); %></span></p>
</script>
Anyone know why this error is happening. I have looked at some other people using this style and it seems correct but maybe I'm missing a symbol?
Note: Fixed the issue.
My code had a =
sign in the wrong place.
<%= _.each(info.items, function(books) { %>
should be:
<% _.each(info.items, function(books) { %>
Not sure why you need the =
for some areas and not for others. Maybe someone can explain.
example in this area of the code I need to use a =
sign :
<%= books.name + ", " %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用默认设置,当您执行
<%= variable %>
时,它只会打印出variable
的值。要评估(即运行一段 Javascript 代码),您需要执行
<%alert('something') %>
With the default settings, when you do
<%= variable %>
it just prints out the value ofvariable
.To evaluate (i.e. run a piece of Javascript code) you do
<% alert('something') %>
<%=variable%>
是<%printvariable%>
的下划线简写<%= variable %>
is underscore shorthand for<% print variable %>