我在 React 中遇到了 indexedDB 的问题。我有一个用于保存参数的数据库,并且必须每天为每个用户保留一个参数。所以我决定为数据库的一个key设置一个
dateAndId
。我的数据库架构:
{
store: "dataTime",
storeConfig: { keyPath: "dateAndId", autoIncrement: false},
storeSchema: [
{ name: "parameters", keypath: "parameters", options: { unique: false } },
],
}
update
功能我没问题。我用下面的代码更新数据库。它正在寻找相应的对象并更新它。
update({
dateAndId: currentDate + '-' + UserInfo.id,
parameters: {
...UserInfo.parameters,
},
}).then(
(event) => {
console.log("timeData updated: ", event);
}
);
但是当我使用
getByID
和getByIndex
时,会弹出错误提示:找不到相应的对象
例如
getByIndex
我得到
当我使用
getByID
我得到
虽然我确定参数是一个有效的键,因为它是一个字符串。
这是我
getByID
的代码:
useEffect(() => {
getByID(String(currentDate + '-' + UserInfo.id)).then(data => {
UserInfo.setParameters(data);
});
}, []);
你认为确切的问题是什么?我觉得很简单但是我看不出来
预先感谢您的帮助