我正在開發一個庫存應用程式并嘗試在delete單擊字體真棒圖示時從 mongodb 中洗掉專案。
我查看了 MDN 檔案本地庫專案
Category_detail.pug
extends layout
block head
link(rel="stylesheet", href="/stylesheets/category_detail.css")
<script src="https://kit.fontawesome.com/abb39a57a2.js" crossorigin="anonymous"></script>
block content
h1 #{category.name}
table
thead
tr
th Item name
th Price
th Update
th Delete
tbody
each item in items
tr
td #{item.itemName}
td #{item.price}
td
//- Update iten details
a(href="#")
i(class="fas fa-edit")
td
//- Delete item
form(method="POST" action='')
div.form-group
input(type="hidden", name='itemid',required="true", value=item._id )
a()
i(class="fas fa-trash" type='submit')
//- a(href="#")
//- i()
如果您想查看任何其他檔案,這是我的github
uj5u.com熱心網友回復:
我不知道什么是哈巴狗,但我知道 HTML .. 我也是 菜鳥.. 首先,我們不能點擊標簽..所以,我們可以在錨標簽上添加一個點擊功能并撰寫我們的邏輯。 .(在你的情況下,這是一個洗掉邏輯)。
uj5u.com熱心網友回復:
我解決了。這是更新圖示的代碼
哈巴狗檔案
td
//- Update iten details
a( href=`/categories/${category._id}/update/${item._id}` class="updatebtn" data-updateid=`${item._id}`)
i(class="fas fa-edit")
我只是添加href到包含被點擊id的專案的錨標簽。之后在后端我用來req.param.id獲取點擊的特定專案的 id。
專案控制器
exports.itemUpdate_get = (req, res)=>{
Items.findById(req.params.id)
.populate('category')
.exec(function(err, data){
res.render('item_form', {itemData: data});
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/390755.html
上一篇:如何解決Nodejs中的net::ERR_ABORTED404
下一篇:在NestJs中使用連接閃存
