为什么这个 lodash 模板会抛出语法错误?我觉得不错
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'));
然而它抛出 "Uncaught SyntaxError: Unexpected token {" 异常。我在这里疯了吗?不幸的是,我似乎无法为我的编辑器 (Sublime Text) 找到合适的 linter/syntax 荧光笔,并将此代码粘贴到在线验证器中会给我完全相同的错误。
将elseif
替换为else if
..
这个模板对我来说非常好:
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 荧光笔,并将此代码粘贴到在线验证器中会给我完全相同的错误。
将elseif
替换为else if
..