如何通过JavaScript中的承诺获得特定的VAR/常数价值

发布于 2025-02-09 13:30:06 字数 462 浏览 1 评论 0原文

我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2025-02-16 13:30:06

您为什么不只是使用Python的请求

在JavaScript中,response.json()也返回一个诺言,因此您需要另一个

fetch("https:url-here").then(res => res.json()).then(json => 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:

fetch("https:url-here").then(res => res.json()).then(json => json)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文