如何通过JavaScript中的承诺获得特定的VAR/常数价值
我正在尝试使用Promise检索Statelist变量值。 我正在使用stramlit_javascript(python库)来运行承诺。
在下面显示的URL的JavaScript中,具有statelist变量。我需要使用响应函数来检测该功能。 下面的代码显示了我的响应功能。它显示出错误,未定义的统计员。
return_value = st_javascript("""await fetch("http://localhost:8501").then(function(response){
console.log("Success!", response);
return response.json($statelist); });""")
这是变量的代码,我需要检测。
var statelist = new Set()
statelist.add('Kansas')
I am trying to retrieve statelist variable value, using promise.
I am using streamlit_javascript (python library) to run the promise.
In javascript of the below shown URL, has the statelist variable. I need to retrive that using the response function.
Below code shows my response function. Its showing an error, statelist not defined.
return_value = st_javascript("""await fetch("http://localhost:8501").then(function(response){
console.log("Success!", response);
return response.json($statelist); });""")
Here is the code of the variable, what I need to retrive.
var statelist = new Set()
statelist.add('Kansas')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您为什么不只是使用Python的
请求
?在JavaScript中,response.json()也返回一个诺言,因此您需要另一个
。
Why don't you just use python's
requests
?In javascript, response.json() also returns a promise so you'll need another
.then()
like this: