2016-05-13 25 views
0

我嘗試在Lokijs中使用我現有的數據庫,但是我的autoloadcallback不會使用console.log('from add collection don')知道它什麼時候會啓動,但它永遠不會劑量,當我嘗試添加時數據DB它失敗,只有當我在本地Lokijs autoloadcallbake not woking

var user = null 
 
     db = new loki("myuser.json",{adapter: adapter}, { 
 
     autosave: true, 
 
     autosaveInterval: 5000, 
 
     autoload: true, 
 
     autoloadCallback: function(){ 
 
      db_ready = true; 
 
      console.log('from add collection don') 
 
      if(db.getCollection("myaccount") == null){ 
 
       myusers = db.addCollection("myaccount"); 
 
      } 
 
     
 
     } 
 
    });

function py_userlogin(username,password,islogin){ 
 
     myusers.insert({ 
 
      username:username, 
 
      password:password, 
 
      islogin:islogin 
 
     },function(err,don){ 
 
      console.log(JSON.stringify(err) + JSON.stringify(don)) 
 
     }); 
 
     console.log(myusers.data); 
 
     db.saveDatabase(); 
 
    }

設置我的集合變量工作3210

回答

1

你的第三個變量是不存在的設置選項,它應該是唯一的:

new loki(file, [options]); 

adapter是一個選項,只是和其他人一樣,就像這樣:

var user = null 
     db = new loki("myuser.json",{ 
     adapter: adapter, 
     autosave: true, 
     autosaveInterval: 5000, 
     autoload: true, 
     autoloadCallback: function(){ 
      db_ready = true; 
      console.log('from add collection don') 
      if(db.getCollection("myaccount") == null){ 
       myusers = db.addCollection("myaccount"); 
      } 

     } 
    }); 

乾杯