gpt4 book ai didi

javascript - IndexedDb - 检查表是否存在并包含数据

转载 作者:行者123 更新时间:2023-11-30 13:19:38 33 4
gpt4 key购买 nike

在我的应用程序首次运行时使用 IndexedDB 我用一些数据填充它,我想确保在创建数据库和表时它们不存在。

我可以在 JavaScript 中查询表的长度以查看它是否包含和数据吗?

最佳答案

我们可以使用 IndexDB 的 objectStoreNames 属性来检查 ObjectStore 是否存在。

var db_object, object_store;
if( !db.objectStoreNames.contains(currentobjectstore) )
{
db_object = i_db.createObjectStore(currentobjectstore, {autoIncrement:true} );
object_store = db.transaction(currentobjectstore, 'readwrite').objectStore(currentobjectstore);
} else {
object_store = db.transaction(currentobjectstore, 'readwrite').objectStore(currentobjectstore);
}

关于javascript - IndexedDb - 检查表是否存在并包含数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687315/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com