@H_404_1@
我有一些静态数据,我使用DB浏览器为sqlite创建了一个sqlite数据库文件.现在想在我的Ionic 2应用程序中使用那个sqlite数据库文件.
我查看了https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10帖子但没有得到解决方案.
谁能帮帮我吗!!!
离子信息:
@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控制器/工厂/服务回调中尤其棘手,这些回调可能在触发deviceready事件之前触发.
这是详细的例子.