我正在使用IndexedDB,并在只想添加新对象的地方创建了此函数。
var request = indexedDB.open("db", 1);
request.onsuccess = function(event){
request = event.target.result;
var transaction = request.transaction(["cart"], "readwrite");
var store = transaction.objectStore("cart");
var obj = {
w : w,
x : x,
y: y,
z: z
};
var requestAdd = store.add(obj);
requestAdd.onsuccess = function(w){
console.log("great");
}
request.close();
}
这是我创建索引和objectStore的方式
var storeCart = db.createObjectStore("cart", { autoIncrement : true });
storeCart.createIndex("w", "w", {unique: false});
storeCart.createIndex("x", "x", {unique: false});
storeCart.createIndex("y", "y", {unique: false});
storeCart.createIndex("z", "z", {unique: false});
但是,由于某种原因,当我尝试访问cart
时出现此错误:
NotFoundError: The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.
我该如何解决?
答案 0 :(得分:0)
也许问题是您需要在request.onupgradeneeded事件中创建objectStore和索引。
要触发该事件,您需要首次创建indexedDB或在调用 listoffiles = glob.glob('C:/Users/riley/Desktop/mydata//*.csv') #glob allows you to create a list of files/folders that match wildcard expression in this case all the csv files in the directory
# Create donors directory
donors = {}
for filename in listoffiles:
with open(filename) as file:
for line in file:
# line processing stuff
data = line.split(',')
donor = ''.join(data[3,5,7])
# populate data structure
if donor in donors:
donors[donor].append(data)
else:
donors[donor] = [[data]]
时更改indexedDB版本:
indexedDB.open()