我想从indexedDB中获取由键定义的条目的值。我要在其中提取值的代码如下:
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()方法正在提取某些东西。但是我希望变量mystorage应该只是IndexedDB条目的值。
到目前为止,我所做的事情确实可以解决问题: -阅读有关indexedDB中的get()方法的文档 -关于stackoverflow的一篇文章讨论了这个问题。但我无法解决问题
答案 0 :(得分:-1)
我自己解决了这个问题:
db.transaction("Off-DB").objectStore("Off-DB").get(4).onsuccess = function(event) {
console.log("Your value is:" + event.target.result.value);
};
使用此代码,您可以获得indexedDB的键4的值。