Javascript 如何根据mongoDB中的对象数量连续对表进行编号?
我有一个表,并希望根据mongoDB中的记录数量对其进行编号。除了编号外,一切都正常 我尝试了循环和长度,但它破坏了我的应用程序 我的模式:Javascript 如何根据mongoDB中的对象数量连续对表进行编号?,javascript,node.js,mongodb,ejs,Javascript,Node.js,Mongodb,Ejs,我有一个表,并希望根据mongoDB中的记录数量对其进行编号。除了编号外,一切都正常 我尝试了循环和长度,但它破坏了我的应用程序 我的模式: var userInputSchema = new mongoose.Schema({ name: String, address: String, phone: Number }); 列“#”应该根据mongoDB中记录的数量自动编号,但我无法使其正常工作。 它是空的或将以“内部服务器错误”破坏整个页面。尝试使用方法的索
var userInputSchema = new mongoose.Schema({
name: String,
address: String,
phone: Number
});
列“#”应该根据mongoDB中记录的数量自动编号,但我无法使其正常工作。
它是空的或将以“内部服务器错误”破坏整个页面。尝试使用方法的索引参数
#
名称
地址
电话
你需要在打印之前增加索引。投票表决后,我删除了我的答案,我忘记了“在打印之前增加索引”部分:是的,我在发布我的答案后看到了你的答案。我的答案和你的答案是一样的。太好了,谢谢你的工作,也谢谢玛根的帮助!我还是一个初学者。。。(此外,我忘记了遇到相同问题的任何人的“=”)
<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
<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, index) { %>
<tr>
<th scope="row"><%=++index %></th>
<td><%=userInput.name %></td>
<td><%=userInput.address %></td>
<td><%=userInput.phone %></td>
</tr>
<% }); %>
</tbody>