2016-05-26 23 views
1

我想用某些json數據構建某種離線應用程序,我希望在應用程序的生命週期首次加載時填充我的數據庫。我用pouchDb離子2,則i加入PouchDB負載插件及其工作精細與此代碼:如何在離子2中處理加載的PouchDB數據,並在PouchDB檢查器中看到它們

let PouchDB = require('pouchdb'); 
PouchDB.plugin(require('pouchdb-load')); 


initDB() { 

    this._db = new PouchDB('cities3', { adapter: 'websql' }); 
    this._db.load('../../../assessts/cities.json').then(function() { 

     console.log("Done loading!"); 
    }).catch(function (err) { 
     console.log("error while loading!") 

    }); 

輸出將被完成加載!但是當我要檢查在PouchDB檢查數據,我會得到這個錯誤:

No PouchDB found 

To use the current page with PouchDB-Fauxton, window.PouchDB needs to be set. 

我知道我應該使用窗口[「PouchDB」] = PouchDB;但我的問題是,其中

+1

它添加在你的應用程序的根源,我會做:'window.PouchDB =需要( 'pouchdb')'。儘管只要在打開檢查器之前初始化'window.PouchDB',它就可以在任何地方工作。 –

+0

或'window.PouchDB = PouchDB' – bfredo123

回答

0

你應該後 this._db = new PouchDB('cities3', { adapter: 'websql' });