我想从indexedDB中获取key定义的条目的值。我想要提取值的代码如下所示:
request.onsuccess = function (event) {
db = request.result;
transaction = db.transaction("Off-DB", "readwrite");
store = transaction.objectStore("Off-DB");
db.onerror = function(event){
console.log("ERROR" + event.target.errorCode);
}
store.put({value: data});
var mystorage = store.get(1);
transaction.complete = function() {
db.close();
}
}
我认为该代码到目前为止工作,因为我解决了调试我的程序:
get() - Method正在提取一些东西。但我想在变量mystorage中应该只是IndexedDB条目的值。
到目前为止我所做的事情确实解决了这个问题: - 读取有关get() - indexedDB中的方法的文档 - stackoverflow上有一篇文章讨论了这个问题。但我无法解决它的问题
我自己解决了这个问题:
db.transaction("Off-DB").objectStore("Off-DB").get(4).onsuccess = function(event) {
console.log("Your value is:" + event.target.result.value);
};
使用此代码,您将获得indexedDB的key 4的值。