我遵循PouchDB安裝和SQLite的所有步驟。我現在面臨以下問題:離子2上的PouchDB + SQLite問題
1)this._db.info(),然後(console.log.bind(控制檯)) - 顯示適配器:的WebSQL,sqlite_plugin:假
Object
adapter:"websql"
auto_compaction:false
db_name:"bakbak"
doc_count:15
sqlite_plugin:false
update_seq:15
websql_encoding:"UTF-8"
我不是確定我做錯了什麼。
2)應用程序在Chrome上正常運行。在Firefox上它拋出一個錯誤:this.db.sync不是一個函數。我將其更改爲PouchDB.sync,然後錯誤消失。爲什麼發生? 3)在Firefox和IE上完成上述更改後,我得到「EXCEPTION:錯誤:未捕獲(承諾):錯誤:適配器丟失」。
是這個bug解決:https://groups.google.com/forum/#!searchin/pouchdb/sqlite/pouchdb/-ROWHfB3Ty0/6qEfRkf6MTkJ
我試圖按照這裏的建議是:Ionic PouchDb Sqlite plugin issue
但我沒有任何pouchdb庫在我的index.html進口。它不在js文件夾中。我可以在node-modules文件夾中找到它。
<body>
<ion-app></ion-app>
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<!-- Polyfill needed for platforms without Promise and Collection support -->
<script src="build/js/es6-shim.min.js"></script>
<!-- Zone.js and Reflect-metadata -->
<script src="build/js/angular2-polyfills.js"></script>
<!-- the bundle which is built from the app's source code -->
<script src="build/js/app.bundle.js"></script>
</body>
我作了如下改變,以使sqlite2插件:
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var db;
alert("window.cordova: " + window.cordova);
alert("window.SQLitePlugin: " + window.SQLitePlugin);
if (window.cordova && window.SQLitePlugin) { // because Cordova is platform specific and doesn't work when you run ionic serve
db = window.sqlitePlugin.openDatabase({ "name": "bakbak" }); //device - SQLite
alert("device db (SQLite) loaded");
} else {
db = window.openDatabase("APSNetMobileDb", "1.0", "bakbak", 100 * 1024 * 1024); // browser webSql, a fall-back for debugging
alert("browser db (WebSQL) loaded");
}
</script>
警報顯示,科爾多瓦和SQLite是未定義
嗨Nolan - 我已經添加了SQLite插件2,它仍然顯示相同的錯誤。我試圖定義:window.sqlitePlugin但我做不到。我發現這段代碼:var db = window.sqlitePlugin.openDatabase({name:「demo.db」});我得到這個錯誤:無法讀取未定義的屬性'openDatabase'。我一定做錯了什麼。請幫忙。 –
我設置了window.sqlitePlugin,但仍然出現相同的錯誤。在window.sqliteplugin的設置中,它顯示該插件未加載。 –
對不起,我不知道爲什麼插件沒有加載。您可能想閱讀[本教程](http://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-ionic-2/)或嘗試[使用SQLite的示例Cordova應用程序貯藏】(https://github.com/nolanlawson/pouchdb-cordova-hello-world-with-sqlite-plugin)。 – nlawson