我正在尝试使用Electron创建一个桌面GUI,以从javascript API包装器接收和提交数据。包装器使用异步命令,这使得在尝试使用html / css接收并以文本形式在GUI上打印数据时出现问题。
我需要从异步命令中获取数据,然后将其转换为html文本以清晰地显示给用户。
如果我可以找到一种通过异步函数创建全局变量的方法,或者至少从作用域返回它,那么我应该能够使其工作。但是我无法为自己的生活弄清楚这一点。我无法将整个文件包装在异步函数中,因为它需要使用id标记链接回一些html文本。
现在我对这个卡住了一段时间,通常我想自己弄清楚这些事情,但是我放弃了这个。我感谢一个好心人愿意给予的帮助!谢谢!
这是我正在使用的javascript API包装器,以防它对回答以下问题很有用:https://github.com/binance-exchange/binance-api-node
我尝试使用本地存储和会话存储(桌面应用程序不支持它,因为它不是Web浏览器),尝试使用global.sharedObject方法,尝试使用回调,并尝试将其存储在窗口中。变量。所有这些方法都会给我带来错误。
<html>
//the text that will be displayed
<td id="valETHBTC"></td>
</html>
<script>
//Import the module and create a new client
const Binance = require('binance-api-node').default
const client = Binance()
<script>
<script>
//variable to be made global
var globalVar;
//my async function
async function yeet()
{
//I'm trying to take this variable out of local scope
globalVar = await client.avgPrice({ symbol: 'ETHBTC' });
}
yeet(); //calling the yeet function
//set the valETHBTC tag text equal to our globalVar
document.getElementById("valETHBTC").innerHTML = globalVar;
</script>