未捕获的SyntaxError:意外的标识符Underscore _.template

时间:2011-07-24 00:16:56

标签: javascript underscore.js

我正在使用Underscore库并使用其模板功能。

但是我遇到了一个奇怪的问题Uncaught SyntaxError: Unexpected identifier。产生此问题的代码是:

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');

我尝试过所有事情,但无法确定问题。

1 个答案:

答案 0 :(得分:3)

它是if (product.images && product.images.length)而不是if (product.images and product.images.length);)

相关问题