3

我正在尝试将 indexedDB 与jax webGL 框架一起使用,但由于某种原因 setVersion 不起作用。

这是相关的咖啡脚本

if @indexedDB and @objectStore and @key
  idb_request = indexedDB.open @indexedDB
  idb_request.onsuccess = (e) =>
    idb = e.target.result

    if idb.objectStoreNames.contains @objectStore
      store = idb.transaction([@objectStore], IDBTransaction.READ_WRITE).objectStore(@objectStore)

    else

      console.log idb.version # => ""

      version_request = idb.setVersion(0.1)
      version_request.onblocked = (e) -> console.log e #=> this one fires
      version_request.onerror = (e) -> console.log e
      version_request.onsuccess = (e) -> console.log e
      version_request.onfailure = (e) -> console.log e

  idb_request.onerror = (e) -> console.log "ERROR: Unable to open indexedDB"

...

附加到触发的版本请求的唯一处理程序是 onblocked,但我什至不确定请求被阻止意味着什么或为什么会发生这种情况......

为什么版本请求会被阻止?

4

2 回答 2

1

根据 IndexedDB 规范,blocked如果在发出版本更改请求时数据库连接仍处于打开状态,则可能会发送事件。请参阅:http ://www.w3.org/TR/IndexedDB/#version_change-transaction-steps

这是规范中的文本:

3. If running asynchronously and any of the connections in openDatabases are still not closed, queue up a blocked event for the request.

FWIW:我无法在 Jax 中重现此问题;我知道最好不要说这是不可能的,但目前看起来不太可能是框架中的错误。对应的 Jax 问题为:https ://github.com/sinisterchipmunk/jax/issues/37

于 2011-12-08T02:37:28.777 回答
1

以下是使用 IndexedDB 开发时保持数据库连接打开的两种常用方法:

1)打开多个标签。

2)不小心打开数据库两次。

于 2011-12-08T03:59:48.960 回答