我如何使用下划线模板(<%%>),就像我在PHP中使用它一样(lt;?PHP?>

how can I use underscore template (<%%>) way I use it in PHP (<?php ?>)

本文关键字:gt PHP lt 一样 何使用 下划线      更新时间:2023-09-26

如何修复此问题?

<%= if(comments.length) { %>
  <%=_.each(comments, function (comment) {%>
    <div><%=comment.message%></div>
  <%=});%>
<%=}%>

我可以在PHP中这样做:

<?php if(count($comments) { ?>
  <?php foreach ($comments as $comment){ ?>
     <div><?=$comment->message?></div>
  <?php } ?>
<?php } ?>

感谢

<% if(comments.length) {
  _.each(comments, function (comment) { %>
    <div><%=comment.message%></div>
  <% });
} %>

也许这就是你想要的
<%=的中删除评估=

<% if(comments.length) { %>
  <% _.each(comments, function (comment) {%>
    <div><%=comment.message%></div>
  <% }); %>
<% } %>