IDBIndex: locale 屬性
已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。
非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。
IDBIndex 介面的只讀屬性 locale 返回索引的區域設定(例如 en-US 或 pl),前提是在建立該索引時指定了 locale 值(參見 IDBObjectStore.createIndex() 的 options 引數)。請注意,此屬性始終返回當前在此索引中使用的區域設定,換句話說,它永遠不會返回 "auto"。
值
字串。
示例
在以下示例中,我們打開了一個事務和一個物件儲存,然後從一個簡單的聯絡人資料庫中獲取了索引 lName。然後,我們使用 IDBIndex.openCursor 在該索引上打開了一個基本遊標——這與直接在 ObjectStore 上使用 IDBObjectStore.openCursor 開啟遊標的工作方式相同,但返回的記錄是根據索引排序的,而不是主鍵。
locale 值將被記錄到控制檯。
js
function displayDataByIndex() {
tableEntry.textContent = "";
const transaction = db.transaction(["contactsList"], "readonly");
const objectStore = transaction.objectStore("contactsList");
const myIndex = objectStore.index("lName");
console.log(myIndex.locale);
myIndex.openCursor().onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
const tableRow = document.createElement("tr");
for (const cell of [
cursor.value.id,
cursor.value.lName,
cursor.value.fName,
cursor.value.jTitle,
cursor.value.company,
cursor.value.eMail,
cursor.value.phone,
cursor.value.age,
]) {
const tableCell = document.createElement("td");
tableCell.textContent = cell;
tableRow.appendChild(tableCell);
}
tableEntry.appendChild(tableRow);
cursor.continue();
} else {
console.log("Entries all displayed.");
}
};
}
規範
目前不是任何規範的一部分。
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。