【问题标题】:Pre-populated database in ionic 2ionic 2 中的预填充数据库
【发布时间】:2018-02-01 22:29:33
【问题描述】:

我有一些静态数据,我使用 DB Browser for 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

【问题讨论】:

标签: angular sqlite ionic2 cordova-plugins


【解决方案1】:

你可以使用

cordova-sqlite-ext

用于安装,

cordova plugin add cordova-sqlite-ext --save

一个 Cordova/PhoneGap 插件,用于打开和使用 sqlite 数据库 带有 REGEXP (Android/iOS) 和预填充的 Android/iOS/Windows 数据库(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

【讨论】:

    猜你喜欢
    • 2016-10-24
    • 2022-07-07
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 2018-01-06
    相关资源
    最近更新 更多