在内部更新。在javaScript中不反映在外面
我尝试在“ fetch”中更新内部“。 - 执行put-in-idbobjectStore-the-transaction-has-has-has-has fined'>后链接。更新“。然后”之外的索引edDB数据。 因此,我创建了一个布尔变量,并尝试在“。然后”内部更新它,并考虑过在外部更新索引的数据,但是布尔值未在“。然后”内部更新。
.then(() =>{
data_inserted = true ;
})
Now outside the ".then"
console.log(data_inserted); // value is false
if ( data_inserted === true )
{
// update IndexedDB code
}
I saw this post
请帮助我更新布尔变量。
提前致谢。
I tried updating IndexedDB data inside ".then" in fetch but that doesn't work inside event handlers as I got to know that from this post post-link. Updating the IndexedDB data outside the ".then" is working.
So I created a boolean variable and tried updating it inside the ".then" and thought of updating the IndexedDB data outside but the boolean value is not getting updated inside the ".then".
.then(() =>{
data_inserted = true ;
})
Now outside the ".then"
console.log(data_inserted); // value is false
if ( data_inserted === true )
{
// update IndexedDB code
}
I saw this post post-link and I'm not sure how to do a callback function as they did for my code.
Kindly help me in updating the boolean variable.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这缺乏对异步代码的了解。
异步代码,将在跟随它的代码之后发生。注意:
会输出:
为什么?因为“ then”中的代码直到``somefuncunthattakeseonecond''完成并实现了诺言。但是,在异步块之后的代码将同步运行(即马上:马上)。
您可能希望使用异步/等待/等待 -
等待
停止执行,直到异步函数模式
返回
。 /placeel-assynchronous-javascript/“ rel =“ nofollow noreferrer”> https://blog.logrocket.com/understanding-asynchronous-javascript/
I suspect this is a lack of understanding of async code.
The async code,
then
, will happen AFTER the code that follows it. Note:Will output:
Why? Because the code in the 'then' won't run until after `someFunctionThatTakesOneSecond" completes and the promise is fulfilled. But the code after the async block will run synchronously (ie: right away).
You may wish to use the async/await pattern instead -
await
stops further execution until the async function returns.So:
Would output:
Read more on async/await and asynchronous JavaScript here: https://blog.logrocket.com/understanding-asynchronous-javascript/