gpt4 book ai didi

mysql - 如何在nodejs中的html表中显示mysql查询结果?

转载 作者:行者123 更新时间:2023-11-30 21:49:26 26 4
gpt4 key购买 nike

以下是 Nodejs 中的查询结果示例。

Node :

 [ RowDataPacket {
id: 1,
booktitle: 'Leading',
bookid: '56353',
bookauthor: 'Sir Alex Ferguson' },
RowDataPacket {
id: 2,
booktitle: 'How Google Works',
bookid: '73638',
bookauthor: 'Eric Smith' },
RowDataPacket {
id: 3,
booktitle: 'The Merchant of Venice',
bookid: '37364',
bookauthor: 'William Shakespeare' } ]

我需要这些数据以下面的html格式显示

booktitle               bookid         bookauthor
-----------------------------------------------------------
Leading 56353 Sir Alex Ferguson
How Google Works 73638 Eric Smith
The Merchant of Venice 37364 William Shakespeare

我尝试使用以下代码分别获取键和值

 for(var i = 0; i < JSONObject.length; i++) {
for(var val in JSONObject[i]) {
console.log(JSONObject[i][val])
}
}

但这并没有像预期的那样工作。我的数据将是动态的。键和值将不断变化。所以我不能像那样访问 JSONObject[i].booktitle 的值。我怎样才能得到一个通用的解决方案?如何以表格格式显示数据。

最佳答案

for(var i = 0; i < JSONObject.length; i++) {
for(var j = 0; j < JSONObject[i].length; j++) {
for(var val in JSONObject[i][j]) {
alert(val)
alert(JSONObject[i][j][val])
}
}
}

关于mysql - 如何在nodejs中的html表中显示mysql查询结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47918503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com