0
我試圖在EJS中執行一個簡單的操作,如果集合存在,則在集合上執行for循環。null集合上的EJS循環仍然評估?
<% if(typeof applicant.customerContacts != 'undefined'
&& applicant.customerContacts) { %>
<% applicant.customerContacts.forEach(function(contact) { %>
<div>
//stuff goes here
</div>
<% } %>
<% } %>
但是我一直在運行時收到此錯誤:
[SyntaxError: missing) after argument list in {redacted}/applicantOverview.ejs while compiling ejs]
我如何編寫循環來處理,如果該數據可能爲空/從對象失蹤?