[英]Using variable from EJS in and EJS if statement
基本上,我無法弄清楚如何在 EJS if 語句中使用 EJS“變量”(不知道它的真實名稱。在我的情況下它是<%=postContent[i]%>
),如下所示。
<% for (i = 0; i <= 10; i++) { %>
<% if (<%-postContent[i]%>.includes('gyfcat')) { %>
<div>PLACEHOLDER</div>
<% } else { %>
<img src="<%=postContent[i]%>" class="redditImages">
<% } %>
<% } %>
我基本上想要它,所以當字符串"gyfcat"
在postContent
字符串(它是一個 URL)中時,第一個代碼塊運行,否則運行<img>
代碼。
我得到的Error: Could not find matching close tag for "<%".
是Error: Could not find matching close tag for "<%".
只需刪除postContent[i]
周圍的<%=
和%>
postContent[i]
解決我的問題。
<div>
<% if(typeof datas !='undefined') { %>
<% datas.forEach(function(data) { %>
<div> Id:<%= data.id %></div>
<div> Title:<%= data.title %></div>
<div> Body:<%= data.body%></d>
<% }); %>
<% } %>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.