我有一些静态数据,我已经使用 SQLite 数据库浏览器 创建了一个 SQLite 数据库文件。现在想在我的 Ionic 2 应用程序中使用该 SQLite 数据库文件。
我调查了 https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10发帖但没有得到解决方案。
谁能帮帮我!!!
ionic 信息:
@ionic/cli-utils : 1.9.2
ionic (Ionic CLI) : 3.9.2
全局包:
Cordova CLI : 7.0.1
本地包:
@ionic/app-scripts : 2.0.2
Cordova Platforms : none
Ionic Framework : ionic-angular 3.5.3
最佳答案
您可以使用
用于安装,
cordova 插件添加 cordova-sqlite-ext --save
A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/Windows with REGEXP (Android/iOS) and pre-populated databases (Android/iOS/Windows)
var db = null;
document.addEventListener('deviceready', function() {
db = window.sqlitePlugin.openDatabase({name: 'demo.db', location: 'default'});
});
重要:与其他 Cordova 插件一样,您的应用程序必须等待 deviceready
事件。这在 Angular/ngCordova/Ionic controller/factory/service 回调中尤其棘手,它们可能在 deviceready 事件被触发之前触发。
这里有一个详细的例子。
关于angular - ionic 2中的预填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45854856/