0

我创建了一个 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});

这里 res 是一个 javascript 对象,它是被存储的数据。

但是当我下次关闭并重新打开网页时,我想检查这家商店是否存在。如果商店存在,我想检查这个文件是否存在。如何进行这些检查?

谢谢

PS - 有什么好的资源可以让我学习 Lawnchair 吗?

4

1 回答 1

0

最后经过多次试验,我想出了以下几点:

// 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 {

        }
    });
});

请让我知道这是正确的方法还是有更好的方法。如果您喜欢我的努力,请给我积分:)

于 2014-08-31T04:26:20.443 回答