[英]How to check the number of elements in the array with underscore template
嗨,我有以下陣列:姓名:John,電子郵件:[email@gmail.com,email2@gmail.com]
如果電子郵件數量僅為1或大於1,我想用不同的方式表示此數據。因此,基本上,我想檢查if(number_of_elements_in_email == 1),做點什么,否則做不同的事情。
有人可以告訴我如何使用下划線嗎? 感謝您的時間。
Underscore模板中<% ... %>
內的內容只是JavaScript,因此,如果您的email
是數組,則您會說:
<% if(email.length === 0) { %>
<!-- do "there are no email addresses" stuff -->
<% } else if(email.length === 1) { %>
<!-- do "there is only one email" stuff -->
<% } else { %>
<!-- do "there are several email addresses" stuff -->
<% } %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.