我想設置chrome中使用的indexeddb存儲。但是當我嘗試設置READ_WRITE
事務時,我得到了Uncaught TypeError
。未捕獲TypeError:在使用索引數據庫時在Chrome中輸入錯誤
我一直無法找到使用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
定義。
我喜歡把自己當成IndexedDB的「專家」,我很樂意提供幫助。首先,是objectStore var是否傳遞一個字符串或對實際對象存儲的引用,例如在objectStore創建時返回的對象存儲? – buley 2012-03-16 22:02:27
'objectStore'作爲一個字符串被傳遞。 – 2012-03-17 01:00:44