Javascript Lawnchair:检查存储及其文档是否存在
我创建了一个Lawnchair商店并保存了它。请参阅以下代码:Javascript Lawnchair:检查存储及其文档是否存在,javascript,lawnchair,Javascript,Lawnchair,我创建了一个Lawnchair商店并保存了它。请参阅以下代码: var DB = new Lawnchair({ name: "DB", adapter: ["indexed-db", "webkit-sqlite", "ie-userdata", "blackberry-persistent-store", "dom", "window-name", "gears-sqlite", "memory"] }); DB.save({ key: "resKey", res: res}); 这里re
var DB = new Lawnchair({ name: "DB", adapter: ["indexed-db", "webkit-sqlite", "ie-userdata", "blackberry-persistent-store", "dom", "window-name", "gears-sqlite", "memory"] });
DB.save({ key: "resKey", res: res});
这里res是一个javascript对象,它是存储的数据
但是当我下次关闭并重新打开网页时,我想检查这个商店是否存在。如果存储存在,我想检查此文档是否存在。如何进行这些检查
谢谢
PS-有什么好的资源可以让我学习Lawnchair吗 经过多次试验,我终于得出以下结论:
// create a store //* CORRECT TO USE
DB = new Lawnchair({ name: "DB", adapter: ["indexed-db", "webkit-sqlite", "ie-userdata", "blackberry-persistent-store", "dom", "window-name", "gears-sqlite", "memory"] });
//Save a document/table
DB.save({ key: "resKey", data: res }, function () {
//Access the created store
DB = Lawnchair({ name: "DB", adapter: ["indexed-db", "webkit-sqlite", "ie-userdata", "gears-sqlite", "blackberry-persistent-store", "dom", "window-name", "memory"] });
console.log(DB)
//check if the document exists based on the key we used to create it
DB.exists("resKey", function (e) {
console.log("exists : " + e)
if (e == true) {
//get all records from the store
DB.all(function (r) {
console.log(r);
//remove all document/table from the store
DB.nuke(function () {
console.log("Data nuke-ed");
//check if the document exists based on the key we used to create it
DB.exists("resKey", function (e) {
console.log("exists : " + e)
if (e == true) {
//get all records from the store
DB.all(function (r) {
console.log(r);
});
} else {
console.log("Data deleted");
}
});
});
});
} else {
}
});
});
请让我知道这是正确的方法还是有更好的方法。如果您喜欢我的努力,请给我分:)但是我不知道如何检查商店是否存在,但是我能够检查表/文档是否存在。有人能带我到这里吗?