2014-06-24 19 views
7

Warum habe ich einen Fehler?Fehler beim Ausführen von 'createObjectStore' in 'IDBDatabase'

Mein Code:

var idb = window.indexedDB ||  // Use the standard DB API 
      window.mozIndexedDB || // Or Firefox's early version of it 
      window.webkitIndexedDB; // Or Chrome's early version 

var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; 
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange; 

var dbName='nameDb'; 

var idbRequest=idb.open(dbName,'4.67' /*,dbDescription */); 

idbRequest.onsuccess=function (e) { 
    debugger 

    var db=e.target.result; 

    if (!db.objectStoreNames.contains('chat')){ 
     co=db.createObjectStore('chat',{'id':100}); 
    }; 

    if (!db.objectStoreNames.contains('iam')){ 
     co1=db.createObjectStore('iam'); 
    }; 
}; 

idbRequest.onerror = function (e) { 
    debugger 
}; 

Uncaught InvalidStateError: Failed to execute 'createObjectStore' on 'IDBDatabase': The database is not running a version change transaction. index.html:37 idbRequest.onsuccess

+0

"о це за" - was bedeutet das? : D – nicael

+0

Kommentar für mich. –

+0

Ich verstehe alle Ihre Kommentare erwarten dies :-) – nicael

Antwort

13

Sie können einen Objektspeicher in einem Erfolg Befehl erstellen. Sie können dies nur in einem upgrade needed-Ereignis tun.

Zitat von docs:

When you create a new database or increase the version number of an existing database (by specifying a higher version number than you did previously, when Opening a database), the onupgradeneeded event will be triggered. In the handler for this event, you should create the object stores needed for this version of the database

documentation See.

Verwandte Themen