使用纯javascript在全局范围内以变量形式返回Neo4j密码查询结果



我有一个neo4j服务器在docker上运行。我正试图使用在html文件中运行的纯javascript对该服务器执行一些查询。我想获得的是在全局变量中使用查询结果

有了这个变量,我想更新一些<select>html中的选项
返回的查询值如下所示:

{
"type_A" : {
"Sub Assembly" : [
[ "B.1", "descrizione per B.1", 0 ],
[ "B.2", "descrizione per B.2", 1 ],
[ "B.3", "descrizione per B.3", 2 ]
],
"Component" : [
[ "B.1.1", "descrizione per B.1.1", 3 ],
[ "B.2.1.1", "descrizione per B.2.1.1", 6 ]
],
"Assembly" : [
[ "A", "descrizione per A", 12 ],
[ "B", "descrizione per B", 26 ]
]
},
"type_B" : {
"Sub Assembly" : [
[ "C.1", "descrizione per C.1", 8 ],
[ "C.2", "descrizione per C.2", 9 ],
[ "C.3", "descrizione per C.3", 10 ]
],
"Assembly" : [
[ "C", "descrizione per C", 7 ]
]
}
}

第一个<select>将有类型_A和类型_B作为选项,第二个将有例如Sub Assembly、Assembly、Component(如果我在第一个选择中选择类型_A(。根据所做的选择,我将用相应的数组内容填充一个列表
我本来可以执行查询,但现在我被如何使用查询响应所困扰

我尝试过的是(查询只是一个例子,而不是我使用的(

<script type="text/javascript">
// define our fetch functions, and handle our async promises
const driver = neo4j.driver('locahost', neo4j.auth.basic('user', 'password'))
const session = driver.session()
async function getNodes() {
session
.run('MATCH (n) RETURN n.code AS code')
.then(results => {
const output = []
results.records.forEach(res => {
output.push(res.get('code'))
})
console.log(output)
return output
})
.catch(error => {
throw error;
})
.finally(() => {
session.close();
});
}

var out = getNodes().then(res => {
return res
})
console.log(out)
</script>

作为console.log,我得到

Promise {<pending>}
[[Prototype]]:Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: undefined

我想使用一个全局变量,所以我只需要向服务器发出一个请求,就可以获得";准备";并且管理两个<select>改变事件。

这是管理";问题">

如有任何帮助,我们将不胜感激!

在这里的代码中:


async function getNodes() {
session
.run('MATCH (n) RETURN n.code AS code')
.then(results => {
const output = []
results.records.forEach(res => {
output.push(res.get('code'))
})
console.log(output)
return output
})
.catch(error => {
throw error;
})
.finally(() => {
session.close();
});
}

函数getNodes((不返回任何东西。嵌套的promise内部有返回,但实际函数什么也不返回。你可能想把一个";返回";在";会话";