关于在同一脚本中创建各种 IndexedDB objectStores 的最佳方法是什么?我创建了两个对象库:
var opinionObjectStore = thisDb.createObjectStore("opinion", {keyPath: "id", autoIncrement: false});
var commentObjectStore = thisDb.createObjectStore("comment", {keyPath: "id", autoIncrement: false});
然后我打开一个事务并获取两个对象存储:
var transo = myDataBase.transaction(["opinion", "comment"], "readwrite");
var opinionsObjectStore = transo.objectStore("opinion");
var commentsObjectStore = transo.objectStore("comment");
然后我创建我的“需要存储”对象:
var comment = {id: "myid"};
var resp = commentsObjectStore.add(comment);
// other instructions [...]
var opinion = {};
opinion.id = tagElement.id;
var resp = opinionsObjectStore.add(opinion);
我得到一个例外:
DataError: Data provided to an operation does not meet requirements.
[Break On This Error]
var resp = commentsObjectStore.add(comment);
你能帮我让我添加我的评论并且不要抛出异常吗?
在 indexedDB 中添加数据时,我已经阅读了DOM IDBDatabase 异常 5,并且在尝试将数据添加到 indexedDB 时出现错误“提供给操作的数据不符合要求”,这无济于事。