[英]Node.JS Edit User Button Goes to the Same User
我遇到一個問題,我的用戶表上的編輯按鈕移到了同一用戶(我是通過_id值來完成的)。
編輯-我的路由代碼:
router.get('/admin', function (req, res) {
User.find({}, (err, users) => {
if (err) {
console.log(err);
}
}).then((users) => {
res.render('pages/userTable', {users: users});
})
});
我的代碼:
<table id="users" class="table table-striped">
<thead>
<th>Name</th>
<th>Username</th>
<th>Created</th>
<th>Edit User</th>
</thead>
<tbody>
<% users.forEach(user => { %>
<% if (user.enabled == true) { %>
<form method="get" action="users/<%- user._id %>" id="myform">
<tr>
<td><%- user.name %></td>
<td><%- user.username %></td>
<td><%- user.created_at %></td>
<td><input type="submit" name="" value="Remove User" form="myform"></td>
</tr>
<% } %>
<% }) %>
</tbody>
</table>
我的照片:
“刪除用戶”按鈕應導致我單擊的任何用戶,但它始終導致Tom Test。
我怎么了
我認為你最好改變
<input type="submit" name="" value="Remove User" form="myform">
由
<a href="/user/<%= user._id %>" />
而是使用medthod GET的輸入和表單...
您好,我已經檢查了您的代碼,並且我認為您由於未關閉表單標簽而面臨此問題。 一旦您關閉代碼中的表單,就不會遇到此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.