2014-08-30 51 views
0

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

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

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

感谢

PS - 是否有良好的资源在那里我可以学到Lawnchair?

回答

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 { 

     } 
    }); 
}); 

请让我知道这是做正确的方式或者是有更好的办法。如果你喜欢我的努力给我 :)

+0

但我不知道如何检查商店是否存在,但我能够检查表/文件的存在。有人可以在这里指导我吗? – 2014-08-31 20:44:55