未捕获的语法错误:意外的标识符下划线 _.template
我正在使用 Underscore 库并使用它的模板功能。
但我遇到了一个奇怪的问题Uncaught SyntaxError:意外的标识符
。生成此问题的代码是:
window.JST['product_icon'] = _.template('<div\nid="product_icon_<%= product.id %>"\nclass="product_icon itemSpacer"\ndata-product-id="<%= product.id %>">\n\n <div\n class="sticker item hide"\n <% if (product.images and product.images.length) { %>\n style="background-image:url(\'/assets/products/<%= product.images[0].id %>/small/<%= product.images[0].attachment_file_name %>\');"\n <% } %>>\n\n <div class="data-container">\n <small class="id"><%= product.id %></small>\n <div class="description">\n <div class="background"></div>\n <div class="text">\n <a href="#" class="add-to-cart">\n Add to cart\n </a><br/>\n <a href="<%= \'/products/\' + product.permalink %>" class="view-sticker-details">\n View this sticker\n </a>\n <br/>\n <a href="#" class="FPO-load-brands">\n View all brand Stickers\n </a>\n </div>\n </div>\n </div>\n </div>\n</div>\n');
我尝试了所有方法,但无法识别问题。
I am using Underscore library and using its template feature.
But i am getting a strange issue Uncaught SyntaxError: Unexpected identifier
. The code which is generating this problem is:
window.JST['product_icon'] = _.template('<div\nid="product_icon_<%= product.id %>"\nclass="product_icon itemSpacer"\ndata-product-id="<%= product.id %>">\n\n <div\n class="sticker item hide"\n <% if (product.images and product.images.length) { %>\n style="background-image:url(\'/assets/products/<%= product.images[0].id %>/small/<%= product.images[0].attachment_file_name %>\');"\n <% } %>>\n\n <div class="data-container">\n <small class="id"><%= product.id %></small>\n <div class="description">\n <div class="background"></div>\n <div class="text">\n <a href="#" class="add-to-cart">\n Add to cart\n </a><br/>\n <a href="<%= \'/products/\' + product.permalink %>" class="view-sticker-details">\n View this sticker\n </a>\n <br/>\n <a href="#" class="FPO-load-brands">\n View all brand Stickers\n </a>\n </div>\n </div>\n </div>\n </div>\n</div>\n');
I tried every thing but can not identify the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是
if (product.images && product.images.length)
而不是if (product.images and Product.images.length)
;)It's
if (product.images && product.images.length)
and notif (product.images and product.images.length)
;)