javascript - 如何在 Node.js 中将 BigQuery 表数据放入 Dropdown
问题描述
我是 Javascript 的新手。我一直在使用 Node.js 中的 BigQuery 表数据制作动态下拉列表。我已经从 BigQuery 获得了表数据并制作了静态下拉列表,但我不知道如何将表数据放入下拉列表中。有人帮我吗??对不起我糟糕的代码。
index.js
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery({
projectId: 'test_project',
});
bigquery
.dataset("test_table")
.getTables()
.then(results => {
const tables = results[0];
tables.forEach(table => console.log(table.id));
})
.catch(err => {
console.error('ERROR:', err);
});
const list = ["I want to put table data(tables) in here"];
// select tag
let slt = document.getElementById("slt");
addTables(slt);
// return data
function getList() {
return new Promise(function (onFulliflled, onRejected) {
onFulliflled(list);
});
}
function addTables(slt) {
getList()
.then((list) => {
for (item of list) {
// make option
let option = document.createElement("option");
option.text = item;
option.value = item;
// add option
slt.appendChild(option);
}
})
.catch((err) => {
console.error("error", err);
});
}
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>sample</title>
</head>
<body>
<h3>Please choose table</h3>
<select id="slt" name="slt"></select>
<script src="./index.js"></script>
</body>
</html>
解决方案
我用下面的代码解决了这个舞会
function listTables(callback) {
//...
.then(results => {
const tables = results[0];
tables.forEach(table => list.push(table.id));
callback(list);
})
//...
}
listTables(function(list){
});
推荐阅读
- c - 尝试在 C 中执行 RPN 时如何修复分段错误
- r - 在 MCMCglmm 中定义先验
- php - 如何在数组中添加其他数组的元素
- html - NetSuite Saved Search 使用公式(数字)和 html 进行格式化
- c# - 如何在 WPF 桌面应用程序的 System.Windows.Controls.WebBrowser 中显示 pdf 文件(二进制 [])?
- python - 通过 int 值将嵌套列表拆分为子列表
- android - 为什么我的扩展图块扩展到整个屏幕
- android - 如何根据图层列表在启动画面中添加应用程序名称?
- r - R - 按组计算所有数据切割的差异
- amazon-web-services - 如何在没有托管 UI 的情况下使用 aws-amplify API 使用联合身份验证?