Uncaught SyntaxError: неожиданный идентификатор подчеркивает _.template

StackOverflow https://stackoverflow.com/questions/6804150

  •  25-10-2019
  •  | 
  •  

Вопрос

Я использую нижнюю библиотеку и использую его функцию шаблона.

Но у меня есть странная проблема 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');

Я пробовал все, но не могу определить проблему.

Это было полезно?

Решение

Это if (product.images && product.images.length) и не if (product.images and product.images.length) ;)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top