2014-08-30 46 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