问题描述
我有一个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 (将#修改为@)