我正在尝试设置 indexeddb 存储以在 chrome 中使用。但是Uncaught TypeError
当我尝试建立READ_WRITE
交易时,我得到了一个。
我无法找到有关使用 webkitIDB 的最新信息。所以我在这里基本上是盲目的。任何想法我做错了什么?我错过了这方面的好消息吗?
设置:
function OfflineStorage() {
this.saveJSONString = __bind(this.saveJSONString, this);
var request,
_this = this;
this.dbkeyRange = window.webkitIDBKeyRange;
this.dbTransaction = window.webkitIDBTransaction;
this.db = window.webkitIndexedDB;
request = this.db.open("lucidFrog");
request.onsuccess = function(e) {
_this.db = e.target.result;
return _this.setupDB(); //setupDB() ensures the objectStores have been created.
};
}
保存功能:
OfflineStorage.prototype.saveJSONString = function(objectStore, json_string, obj_id) {
var request, store, transaction;
//PROBLEM AREA, gives "Uncaught TypeError: Type error"
transaction = this.db.transaction([objectStore], this.dbTransaction.READ_WRITE, 0);
////////////////////
store = transaction.objectStore(objectStore);
request = store.put({
"json": json_string,
"id": obj_id
});
request.onsuccess = function(e) {
return console.log("YYYYYYEEEEEAAAAAHHHHHH!!!");
};
};
已创建请求objectStore
,并确认this.dbTransaction
已定义。