当我尝试升级数据库时,尽管IDBVersionChangeEvent
抛出了一个事件(它被发送到我的onupgrade
回调),onversionchange
但永远不会被调用!这导致我有一个blocked
事件。我不知道如何让它调用正确的处理程序。
使用 Chrome 27
//Account for different names of indexedDB
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
//Account for different names of transaction and key range
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
var req = indexedDB.open( "test6", 2 );
req.onupgradeneeded = function(event)
{
console.log( "This upgrade gets called" );
//These do nothing
event.target.onversionchange = function(event) { console.log( "request version change" ); };
event.target.result.onversionchange = function(event) { console.log( "database version change" ); };
};
req.onsuccess = function(event)
{
console.log( "This Success is called" );
//These do nothing
event.target.onversionchange = function(event) { console.log( "request version change" ); };
event.target.result.onversionchange = function(event) { console.log( "database version change" ); };
};
req.onerror = function(event)
{
console.log( "This error is not called" );
};
req.onblocked = function(event)
{
console.log( "This blocked is sometimes called" );
};
//This also does nothing
req.onversionchange = function(event) { console.log( "request version change" ); };
我已经尝试在任何地方添加它,但它永远不会被调用!
编辑(未解决)它似乎indexedDB.deleteDatabase()
调用了 onversionchange 处理程序!不知道为什么会这样,但升级不会。