问题描述
只要您使用适当的IDBTransaction,就可以通过单个事务来完成所有事务(而不是打开多个事务(读取表,写入表,写入另一个表等)?
Mozilla说:使事务保持活动状态的唯一方法是在其上发出请求.完成请求后,您将收到一个DOM事件,并假设请求成功,您将有另一个机会在该回调期间扩展事务."这有点模糊.这是否意味着如果我为DOM回调提供了一个事件处理程序,那么我可以在该回调中的任何时候使用事务,而不必担心事务会被关闭?
https://developer.mozilla.org/en/IndexedDB/Using_IndexedDB#Adding_data_to_the_database
IndexedDB事务在触发最后一个回调后立即提交,因此保持它们存活的方法是通过回调传递它们.
我正在从Jonas Sicking采购我的交易信息,Jonas Sicking是IndexedDB的Mozilla开发人员和共同规范作家,他评论了这篇出色的博文表示以下内容:
Instead of opening several transactions (read a table, write to a table, write to another table, etc) is it possible to do this all from a single transaction as long as you are using an appropriate IDBTransaction?
Mozilla says: "The only way to keep the transaction active is to make a request on it. When the request is finished you'll get a DOM event and, assuming that the request succeeded, you'll have another opportunity to extend the transaction during that callback." which is a little vague. Does that mean if I provide an event handler for the DOM callback that I can use the transaction at any point in that callback without ever having to worry about the transaction being closed?
https://developer.mozilla.org/en/IndexedDB/Using_IndexedDB#Adding_data_to_the_database
IndexedDB transactions commit as soon as the last callback is fired, so the way to keep them alive is to pass them along via callbacks.
I'm sourcing my transaction info from Jonas Sicking, a Mozilla dev and co-spec writer for IndexedDB, who commented on this excellent blog post to say the following:
这篇关于如何使indexeddb事务保持活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!