underscore.js template error
I'm trying to load .txt file to <div>
and when .txt have code like this
<h1>Hello <%= name %></h1>
It is working properly, but when I have some code like this
<select name="action_edit" id="task_action_edit">
<option value="none">None</option>
<%
foreach(actions as action) {
if(action['id'] == 2) {
%>
<option selected="selected" value="<%= action['id'] %>" action_abbr="<%= action['title'] %>">
<%= action['title'] %>
</option>
<%
} else {
%>
<option value="<%= action['id'] %>" action_abbr="<%= action['title'] %>">
<%= action['title'] %>
</option>
<%
}
}
%>
</select>
Firefox showing me this error when I'm loading this .txt code to div
missing ) after argument list
[Break On This Error] var __p=[],print=function(){__p开发者_开发知识库.push.a... </select>');}return __p.join('');
underscore.js (line 779)
What I'm doing wrong?
Thanks,
Underscore's templates use JavaScript inside the <% ... %>
delimiters. This:
foreach(actions as action) {
is not JavaScript and that could lead to the odd error you're seeing. Maybe you mean:
for(action in actions) {
in your template.
精彩评论