方法返回的就是一个 IDBTransaction 对象。
var trans1 = db.transaction('foo', 'readwrite');
var trans2 = db.transaction('foo', 'readwrite');
var objectStore2 = trans2.objectStore('foo')
var objectStore1 = trans1.objectStore('foo')
objectStore1.put('1', 'key');
上面代码中,key
对应的键值最终是2
,而不是。因为事务trans1
先于trans2
创建,所以首先执行。
IDBTransaction 对象有以下属性。
IDBTransaction.db
:返回当前事务所在的数据库对象 IDBDatabase。IDBTransaction.error
:返回当前事务的错误。如果事务没有结束,或者事务成功结束,或者被手动终止,该方法返回null
。IDBTransaction.mode
:返回当前事务的模式,默认是readonly
(只读),另一个值是。IDBTransaction.onabort
:指定abort
事件(事务中断)的监听函数。IDBTransaction.oncomplete
:指定complete
事件(事务成功)的监听函数。IDBTransaction.onerror
:指定error
事件(事务失败)的监听函数。
IDBTransaction.abort()
:终止当前事务,回滚所有已经进行的变更。