如何解决使用EJS通过forEach循环显示模式内容
我有一个forEach循环,该循环使用EJS使用mongoDB数据库中的数据呈现表。
一切正常,除了当我打开特定单词的模态时,它只显示第一个单词的模态。我尝试使用EJS更改数据目标和模式ID,但是什么也没发生。
我需要以某种方式获取每个模式以显示与其列表中的单词相对应的数据。
<% nounsList.forEach(function(item){ %>
<tr>
<th scope="row"></th>
<td><%= item.word %></td>
<td>
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target=<%=item._id%>>
Clue
</button>
<div class="modal fade" id=<%=item._id%> tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><%= item.word %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="form-inline" action="/nounClue" method="post" autocomplete="off">
<div class="wordForm form-group mb-2">
<input type="hidden" name="inputId" value=<%= item._id %>>
<input class="form-control" type="text" name="clue" value="" placeholder="add or replace clue...">
</div>
<button class="btn btn-md btn-primary mb-2" type="submit" name="button">Submit</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</td>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。