使用条件语句时的映射
希望有人可以提供帮助,
在我的网站上,用户可以登录并向主页发布通知,然后他们可以看到自己的所有通知以及发布通知的用户。
为了向通知作者显示,我使用下面的地图。
<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>
然后我想说,如果没有通知作者(如该用户已从数据库中删除),我希望它说“作者未知”,
<% if (!notice.author.username) { %>
<p>Author Unknown</p>
<% } else {%>
<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>
<% } %>
但地图似乎在条件语句中停止工作,有什么想法吗???
Hope someone can help,
On my site a user can log in and post a notice to the home page, they can then see all their notices and the user that posted the notice.
To show the notice author I am using the below map.
<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>
Then I'm trying to say if there is no notice author (as in that user was deleted from the database) i want it to say "Author Unknown"
<% if (!notice.author.username) { %>
<p>Author Unknown</p>
<% } else {%>
<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>
<% } %>
but the map seems to stop working in the conditional statement, any idea's???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Javascript 函数应该用
相反,
<%- %> 包裹起来。
如果这不起作用,
请尝试使用 for 循环或 forEach。
Use,
Instead,
The Javascript functions should be wrapped around <%- %>
If that does not work then ,
Try using for loop or forEach.