app.js
function showConnect(req, res){
mysql_crawl.query('SELECT full_price, discount_price, quantity, prod_link, images, prod_desc, status FROM `catalogsearch_fulltext` WHERE MATCH(data_index) AGAINST("ครีม") LIMIT 0 , 10', function(error, rows){
res.render('product.html',{related: rows})
})
产品.html
<%
for (var i of related){
%>
<%= i %>
<%
}
%>
product.html 的结果
[object Object] [object Object]
如何显示product.html中的所有数据(full_price、discount_price、quantity、prod_link、images、prod_desc)
最佳答案
[object Object] 是默认的 toString 结果。您可以做的是使用 JSON.stringify() 或明确说明您想要显示的内容,例如 i.quantity、i.image 等。
<table>
<% for(var i=0; i < related.length; i++) { %>
<tr>
<td><%= related[i].full_price %></td>
<td><%= related[i].discount_price%></td>
</tr>
<% } %>
</table>
关于javascript - 如何使用nodejs和expressjs在mysql上显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43722011/