userRouter.get('/allProducts',function(req,res){
console.log("inside all products")
productModel.find({},function(err,productList){
if(err){
res.send(err);
}
else{
res.send(productList);
}上面的响应对象给出了产品输出,格式如下
[{"productName":"treseme","productType":"shampoo","features":"low
sulphite","price":185,"_id":"5ae09b926b6ad826bc1ce42e","__v":0},
{"productName":"treseme","productType":"shampoo","features":"low
sulphite","price":185,"_id":"5ae09c0a6b6ad826bc1ce42f","__v":0},
{"productName":"pantene","productType":"shampoo","features":"low
sulphite","price":95,"_id":"5ae10e9a1c31142a5c5258b8","__v":0}]我想在HTML文件中以表格的形式显示上面的对象,什么是在node.js中直接以表格的形式查看html的过程。
我想把它显示在简单的超文本标记语言表格format.please中,帮助我摆脱这种情况。提前谢谢。
发布于 2018-04-26 10:24:28
在响应中直接编写您的HTML:
userRouter.get('/allProducts',function(req,res){
console.log("inside all products")
productModel.find({},function(err,productList){
if(err)
return res.send(err);
res.writeHeader(200, {"Content-Type": "text/html"});
productList.forEach( (product) => {
// Write your HTML here
res.write('<span>' + product.productName + '</span><br/>');
});
res.end();
});
});https://stackoverflow.com/questions/50033647
复制相似问题