[英]Why does this lodash template throw a syntax error? It looks fine to me
这个模板对我来说看起来很好:
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'));
但是,它将引发“未捕获的SyntaxError:意外令牌{”异常。 我要疯了吗? 不幸的是,我似乎找不到适合我的编辑器的适当的linter / syntax荧光笔(Sublime Text),并将此代码粘贴到在线验证器中会得到完全相同的错误。
else if
..替换为elseif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.