IDBObjectStore.indexNames

IDBObjectStore 的只读属性 indexNames 返回此对象存储中对象的 indexes 名称(name)列表。

Note: 此特性在 Web Worker 中可用。

Syntax

var myindexNames = objectStore.indexNames;

Value

一个 DOMStringList.

Example

在下面的代码片段中,我们在数据库上打开一个读/写事务并使用 add() 向对象存储添加一些数据。创建对象存储后,我们将打印 objectStore.indexNames 到控制台。有关完整的工作示例,请参阅我们的 待办事项通知应用程序 ( 实时查看示例 )

// 让我们来打开我们的数据库
var DBOpenRequest = window.indexedDB.open("toDoList", 4);

DBOpenRequest.onsuccess = function(event) {
  note.innerHTML += '<li>Database initialised.</li>';
    
  // 将打开数据库的结果存储在db变量中
  // 下面经常用到这个
  db = this.result;
    
  // 运行 addData() 函数将数据添加到数据库
  addData();
};

function addData() {
  // 创建一个新对象以准备插入到IDB中
  var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];

  // 打开读/写数据库事务,准备添加数据
  var transaction = db.transaction(["toDoList"], "readwrite");

  // 当所有事情都完成时,报告事务完成的成功情况
  transaction.oncomplete = function(event) {
    note.innerHTML += '<li>Transaction completed.</li>';
  };


  transaction.onerror = function(event) {
  note.innerHTML += '<li>Transaction not opened due to error. Duplicate items not allowed.</li>';
  };

  // 在事务上创建对象存储
  var objectStore = transaction.objectStore("toDoList");
  console.log(objectStore.indexNames);

  // 请求将 newItem 对象 添加到对象存储区
  var objectStoreRequest = objectStore.add(newItem[0]);

  objectStoreRequest.onsuccess = function(event) {
    // 报告我们请求的成功
    note.innerHTML += '<li>Request successful.</li>';
  };
};

规范

规范 状态 解释
Indexed Database API 2.0
indexNames
Recommendation
Indexed Database API Draft
indexNames
Recommendation

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
indexNamesChrome Full support 24
Full support 24
No support 23 — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 16
Full support 16
No support 10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Partial support 10Opera Full support 15Safari Full support 7WebView Android Full support Yes
Full support Yes
No support ? — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android Full support 25
Full support 25
No support 25 — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android Full support 22Opera Android Full support 14Safari iOS Full support 8Samsung Internet Android Full support 1.5
Full support 1.5
No support 1.5 — 7.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit

Legend

Full support  
Full support
Partial support  
Partial support
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

查看其它内容