【发布时间】:2019-12-25 08:11:33
【问题描述】:
我有一个表,想按我在 mongoDB 中的记录数量对其进行编号。除了编号之外,一切正常...
我尝试了循环和 .length,但它破坏了我的应用程序。
我的架构:
var userInputSchema = new mongoose.Schema({
name: String,
address: String,
phone: Number
});
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">NAME</th>
<th scope="col">ADDRESS</th>
<th scope="col">PHONE</th>
</tr>
</thead>
<tbody>
<% userInputs.forEach(function(userInput) { %>
<tr>
//this won't work <th scope="row"><% userInput[].length %></th>
<td><%=userInput.name %></td>
<td><%=userInput.address %></td>
<td><%=userInput.phone %></td>
</tr>
<% }); %>
</tbody>
</table>
应该是这样的:
# NAME ADDRESS PHONE
1 Gary Evergrenn 123213
2 Tom Street 2333434
3 Fox Jonahill 3434355
“#”列应该根据这个 mongoDB 中的记录数量自动编号,但我不能让它工作。 它是空的,否则会因“内部服务器错误”而破坏整个页面。
【问题讨论】:
标签: javascript node.js mongodb ejs