簡體   English   中英

如何刪除 indexedDB 中的對象存儲?

[英]How to delete an object store in indexedDB?

我在文檔中找不到有關刪除對象存儲的文檔信息,而不是存儲對象而不是數據庫,即刪除對象存儲。 有這種可能嗎?

文檔: https ://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/clear

首先,您需要為 IndexedDB 實例創建一個事務,指定對表的訪問選項。 由於您要操作,請設置:模式的“readwrite”選項mode: IDBTransactionMode ,然后是您要刪除的表的名稱,在我的情況下它稱為“photos_os”

function dropTable() {
    const objectStore = db.transaction('photos_os', "readwrite").objectStore('photos_os');
    const objectStoreRequest = objectStore.clear();

    objectStoreRequest.onsuccess = function(event) {
        console.log('Erase of database completed.');
    };
}

以下是有關如何刪除對象存儲的文檔:

https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM