![](/img/trans.png)
[英]I am trying get price of specific product using ajax call. so far i had tried this. but i am not getting the price after selecting product
[英]I am trying to use search product from DB, in nodejs but the product is not getting?
我正在尝试从数据库中搜索产品,在 nodejs 中,但产品没有得到??? 这是我的代码:这是我在 header 中的搜索容器
用户标头.hbs
<div class="search-container">
<form class="form-inline" action="/search" method="get">
<input class="search-input" id="search-box" type=" search" placeholder="Search..." name="searchTerm"
aria-label="Search" />
</form>
</div>
用户.js
// GET: search box
router.get("/search",async (req, res) => {
try {
let searchTerm = req.body.searchTerm;
let user = req.session.user;
let product= await productHelpers.getAllProducts({Name:{ $search: searchTerm,$options: "i", $diacriticSensitive: true }});
res.render('user/search',{product,user});
console.log('searchTerm>',searchTerm)
console.log('products>',product)
} catch (error) {
res.status(500).send({message: error.message || "Error Occured" });
res.redirect("/");
}
});
来自 user-helpers 的 user-helpers.js 获取 collections 的所有产品
getAllProducts:()=>{
return new Promise(async(resolve,reject)=>{
let products=await db.get().collection(collection.PRODUCT_COLLECTION).find().toArray()
resolve(products)
})
},
search.hbs 搜索结果未得到
<h1 class="pb-4">Search Results</h1>
<div class="row row-cols-2 row-cols-lg-5 g-2 g-lg-3">
<a href="/" class="col text-center category__link">
<div class="category__img category__img--large shadow">
<img src="/product-images/{{product._id}}.jpg" alt="{{product.Name}}" loading="lazy">
</div>
<div class="pt-1">
{{products.Name}} </div>
</a>
</div>
我在 user.js 中的假设代码有问题!
让我猜猜!
{$text: { $search: searchTerm }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.