问题描述
我使用两个不同的事件回调,以便在IndexedDB事务完成或成功时进行响应:
I use two different events for the callback to respond when the IndexedDB transaction finishes or is successful:
让我们说... db:IDBDatabase对象,tr:IDBTransaction object,os:IDBObjectStore object
Let's say... db : IDBDatabase object, tr : IDBTransaction object, os : IDBObjectStore object
tr = db.transaction(os_name,'readwrite');
os = tr.objectStore();
case 1:
r = os.openCursor();
r.onsuccess = function(){
if(r.result){
callback_for_result_fetched();
r.result.continue;
}else callback_for_transaction_finish();
}
情况2:
tr.oncomplete = callback_for_transaction_finish();
如果两者的工作方式类似,这是一种浪费。所以你能告诉我,他们之间有什么区别吗?
It is a waste if both of them work similarly. So can you tell me, is there any difference between them?
推荐答案
虽然这些回调函数类似, : onsuccess
和 oncomplete
之间的区别是事务完成
但是对这些事务做出的请求是成功
。
While it's true these callbacks function similarly they are not the same: the difference between onsuccess
and oncomplete
is that transactions complete
but requests, which are made on those transactions, are successful
.
oncomplete
仅在与交易相关的中定义。一个交易没有
onsuccess
回调。
oncomplete
is only defined in the spec as related to a transaction. A transaction doesn't have an onsuccess
callback.
这篇关于Indexeddb:onsuccess和oncomplete之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!