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