加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 离子2中预先填充的数据库

发布时间:2020-12-17 18:10:42 所属栏目:安全 来源:网络整理
导读:我有一些静态数据,我使用DB浏览器为SQLite创建了一个SQLite数据库文件.现在想在我的Ionic 2应用程序中使用那个SQLite数据库文件. 我查看了https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10帖子但没有得到解决
我有一些静态数据,我使用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-sqlite-ext

安装,

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事件之前触发.

这是详细的例子.

Ionic Framework App With Pre-Filled SQLite DB

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读