【发布时间】:2015-12-18 13:10:14
【问题描述】:
这个模板对我来说看起来非常好:
var renderFormElement = _.template([
'<% if (input.hasOwnProperty("label")) { %>',
'<label class="form__label" for="<%- input.key %>"> <%- input.label %> </label>',
'<% } %>',
'<% if (input.hasOwnProperty("options")) { %>',
'<select name="<%- input.key %>" id="<%- input.key %>">',
'<% _.forEach(input.options, function(option) { %>',
'<option value=""><%- options %></option>',
'<% }); %>',
'</select>',
'<% } elseif (input.hasOwnProperty("type")) { %>',
'<input type="<%- input.type %>"/>',
'<% } %>'
].join('\n'));
但它会引发“Uncaught SyntaxError: Unexpected token {”异常。我在这里疯了吗?不幸的是,我似乎无法为我的编辑器(Sublime Text)找到合适的 linter/syntax highlighter,并且将此代码粘贴到在线验证器中会给我完全相同的错误。
【问题讨论】:
-
阅读How to Ask,按照步骤创建一个最小的、完整的、可验证的示例。如果您仍有问题,请发布。
标签: javascript templates syntax-error underscore.js lodash