我有一些问题与发送数据到数据栏视图。在呈现视图之后,查询是正常的(我已经记录了数据,并且它是正确的),但是我不知道为什么Objectibars视图不包括数据。下面是发送数据和呈现视图的代码:
// GET[]/lichchieu/sua
async suaLichChieu(req,res){
try{
const idLichChieu=req.params.idLichChieu;
const selectedQuerry=`SELECT p.tenPhim,t.idLichChieu,t.ngayChieu,t.caChieu,t.giaPhim,t.ngayThem, c.tenPhongChieu FROM lichchieu t, Phim p , phongchieu c
WHERE t.idPhim=p.idPhim and t.idPhongChieu=c.idPhongChieu and t.idLichChieu=?`;
connection.query(selectedQuerry,[idLichChieu],(err,results)=>{
console.log('Chi tiết',results)
res.render('showtimes/suaLichChieu', {
title: 'Thêm Lịch Chiếu Phim',
objectLichChhieu: results,
});
})
}catch(err){
}
}
下面是来自工具栏视图的代码:
<form action="/lichchieu/sua/{{objectLichhieu.idLichChieu}}?_method=PUT" method="POST" class="container-form-add mx-auto" style="max-width: 900px;">
<div class="row">
<div class="col-sm-12">
<div class="mb-3">
<label class="form-label" for="idPhim">Tên Phim</label>
<input type="text" value="{{objectLichhieu.tenPhim}}">
</div>
<div class="mb-3">
<label class="form-label" for="idPhongChieu">Phòng chiếu</label>
<input type="text" value="{{objectLichhieu.tenPhongChieu}}">
</div>
<div class="mb-3">
<label class="form-label" for="caChieu">Ca Chiếu</label>
<input type="text" value="{{objectLichhieu.caChieu}}">
</div>
<div class="mb-3">
<label class="form-label" for="showDate">Ngày chiếu</label>
<input class="form-control" value="{{objectLichhieu.ngayChieu}}" name="ngayChieu" required name="ngayChieu" id="ngayChieu" type="date" data-date="" data-date-format="DD MMMM YYYY" aria-describedby="helpId" />
</div>
<div class="mb-3">
<label class="form-label" for="price">Giá phim</label>
<input class="form-control" value="{{objectLichhieu.giaPhim}}" required type="number" name="giaPhim" id="giaPhim" aria-describedby="helpId" />
</div>
</div>
</div>
<div class="text-center">
<button class="btn btn-primary" type="submit" style="padding: 10px; min-width: 400px; font-weight: bold; margin: 10px;">Thêm mới</button>
</div>
</form>
1条答案
按热度按时间8ehkhllq1#
我刚刚找到了解决这个问题的方法。因为出于安全原因,Webbar 4.6.0及更高版本限制对原型属性和方法的访问。因此,只需将数据(结果)从SQL查询转换为字符串,然后再将其转换回对象,以确保传递到ObjectiveBar模板的数据不受原型属性和方法的影响。代码如下:
我希望这个解决方案对你们有帮助。