我在roomview.html页面上想要删掉一条显示出来的记录,roomview.html部分代码如下:
<h1>房间列表</h1>
<p>
<a href="/roomview/addroom">增加</a>
</p>
<table>
<thead>
<tr>
<th>_id</th>
<th>roomName</th>
<th>roomContent</th>
<th>roomCreateUser</th>
<th>roomImg</th>
<th>roomCreateDate</th>
<th>roomJoinPeos</th>
<th>roomChat</th>
</tr>
</thead>
<tbody>
<% rooms.forEach(function( room ){ %>
<tr>
<td><%= room._id%></td>
<td><%= room.roomName %></td>
<td><%= room.roomContent %></td>
<td><%= room.roomCreateUser %></td>
<td><%= room.roomImg %></td>
<td><%= room.roomCreateDate %></td>
<td><%= room.roomJoinPeos %></td>
<td><%= room.roomChat %></td>
<td><a href="/roomview/delete?id=<%=room._id%>">删除房间</a> | <a href="/roomview/modifyroom?id=<%=room._id%>">更新房间信息</a></td>
</tr>
<% }); %>
</tbody>
路由roomview.js对应删除部分代码如下:
router.get("/delete/:id",function(req,res){
console.log(req.params.id);
Room.findById(req.params.id,function(err,doc){
if(!doc){
return next(new NotFound("Doc not found"))
}else{
doc.remove(function(){
res.redirect("/roomview");
})
}
});
});
不过当我点击删除房间后页面却显示如下:
Cannot GET /roomview/delete
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…