IDBDatabase:objectStoreNames 属性

注意:此功能在 Web Workers 中可用。

objectStoreNamesIDBDatabase 接口的只读属性,它是一个 DOMStringList,其中包含连接数据库中当前所有 对象存储 的名称列表。

包含连接数据库中当前所有 对象存储 的名称列表的 DOMStringList

示例

js
// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);

// these two event handlers act on the database being opened successfully, or not
DBOpenRequest.onerror = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Error loading database.";
};

DBOpenRequest.onsuccess = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Database initialized.";

  // store the result of opening the database in the db variable. This is used a lot below
  db = DBOpenRequest.result;

  // This line will log the names of the object stores of the connected database, which should be
  // an object that looks like { ['my-store-name'] }
  console.log(db.objectStoreNames);
};

规范

规范
Indexed Database API 3.0
# ref-for-dom-idbdatabase-objectstorenames①

浏览器兼容性

BCD 表格仅在启用 JavaScript 的浏览器中加载。

另请参阅