gpt4 book ai didi

javascript - 我如何在 Electron-js 中从 Sqlite 数据库中获取数据,然后使用 Document.getElementBy ('id' 显示它).innerHTML

转载 作者:行者123 更新时间:2023-12-03 12:39:12 25 4
gpt4 key购买 nike

我如何在 Electrone js 中从 Sqlite 数据库中获取数据,然后使用 Document.getElementBy('id').innerHTML 显示它
处理 Js 文件:

 function show_tables(){
var show_tables_query = "SELECT * FROM tables"
db.get(show_tables_query,function (error,row) {
if(error){
console.log("error")
}
else{
data = []
data.push(row)
for (var i = 0; i < data.length; i++) {
alert('<h1>'+data[i]['table_caption']+'</h1>');
}
}
})}
Index.html 文件
<script src="handle.js"><script>

最佳答案

有多个问题,我想这就是没人想回复的原因:

  • 我认为您使用 sqlite3 module , 那么你想使用 db.all而不是 db.get .
  • 数据在哪里定义?我想你不需要那个。
  • 那么你有一个 for循环一个长度为 1 的数组。你想使用 .all , 命名 rows不是 row并循环 rows .
  • 而不是警报,您想看看 jQuery 或在循环中使用类似的东西:

  •   var newElement = document.createElement('div');
    newElement.innerHTML = '<h1>' + rows[i].table_caption + '</h1>';
    document.body.appendChild(newElement);

    关于javascript - 我如何在 Electron-js 中从 Sqlite 数据库中获取数据,然后使用 Document.getElementBy ('id' 显示它).innerHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63725390/

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