这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

locale 只读特性在 IDBIndex interface returns the locale of the index (for example en-US ,或 pl ) if it had a locale value specified upon its creation (see createIndex() 's optionalParameters .) Note that this property always returns the current locale being used in this index, in other words, it never returns "auto" .

句法

var myIndex = objectStore.index('index');
console.log(myIndex.locale);
					

A DOMString .

范例

In the following example we open a transaction and an object store, then get the index lName from a simple contacts database. We then open a basic cursor on the index using IDBIndex.openCursor — this works the same as opening a cursor directly on an ObjectStore 使用 IDBObjectStore.openCursor except that the returned records are sorted based on the index, not the primary key.

locale value is logged to the console.

function displayDataByIndex() {
  tableEntry.innerHTML = '';
  var transaction = db.transaction(['contactsList'], 'readonly');
  var objectStore = transaction.objectStore('contactsList');
  var myIndex = objectStore.index('lName');
  console.log(myIndex.locale);
  myIndex.openCursor().onsuccess = function(event) {
    var cursor = event.target.result;
    if(cursor) {
      var tableRow = document.createElement('tr');
      tableRow.innerHTML =   '<td>' + cursor.value.id + '</td>'
                           + '<td>' + cursor.value.lName + '</td>'
                           + '<td>' + cursor.value.fName + '</td>'
                           + '<td>' + cursor.value.jTitle + '</td>'
                           + '<td>' + cursor.value.company + '</td>'
                           + '<td>' + cursor.value.eMail + '</td>'
                           + '<td>' + cursor.value.phone + '</td>'
                           + '<td>' + cursor.value.age + '</td>';
      tableEntry.appendChild(tableRow);
      cursor.continue();
    } else {
      console.log('Entries all displayed.');
    }
  };
};
					

规范

Not currently part of any specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
locale 非标 Chrome 不支持 No Edge 不支持 No Firefox 43 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 43 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

非标。预期跨浏览器支持较差。

另请参阅

元数据

  • 最后修改: