无法读取未定义的sqlite ionic-v3和SQLite的属性“ split”

他停了下来

我正在使用ionic-v3和sqlite插件。我试图创建一个简单的数据库,并在其中插入一条记录,然后通过SELECT Query检索该记录。

我遇到的问题是将不会创建数据库,并且将显示一个错误消息“无法读取未定义sqlite的属性”,这将在我第一次编写try&catch时出现在代码中。

$ ionic cordova plugin add cordova-sqlite-storage
$ npm install @ionic-native/sqlite
import { Component } from '@angular/core';
import { NavController, ToastController, Platform } from 'ionic-angular';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  private db: SQLiteObject;
  public movies: string[] = [];
  public message:any;

  constructor(public navCtrl: NavController, private toastCtrl: ToastController, private sqlite: SQLite, platform: Platform) {
    platform.ready().then(() => {
      this.CreateDatabase();
    });
  }

  CreateDatabase()
  {
    try
    {

      this.sqlite.create({
        name: 'data.db',
        location: 'default'
      })
        .then((db: SQLiteObject) => {

          db.executeSql('create table IF NOT EXISTS Movies(id INTEGER PRIMARY KEY, name VARCHAR(32))', [])
          .then(() => {
            console.log('Table Movies created !');
            this.db.executeSql('INSERT INTO `Movies` VALUES (`1`, `James Bond 007`)', [])
            .then(() => console.log('Executed SQL'))
            .catch(e => this.message = e);

        })
        .catch(e => this.message = e);


        })
        .catch(e => this.message = e);
    }
    catch(err)
    {
      this.presentToast(err);
    }

  }

  public retrieveFilms() {

    try 
    {
      this.db.executeSql('SELECT name FROM `Movies`', [])
      .then((data) => {
        if(data == null) {
          return;
        }

        if(data.rows) {
          if(data.rows.length > 0) {
            for(var i = 0; i < data.rows.length; i++) {
              this.movies.push(data.rows.item(i).name);
            }
          }
        }

      }).catch(e => this.presentToast(JSON.stringify(e)));
    }
    catch(err)
    {
      this.presentToast(err);
    }

  }

  presentToast(messageText) {
  let toast = this.toastCtrl.create({
    message: messageText,
    duration: 3000,
    position: 'bottom'
  });

  toast.onDidDismiss(() => {
    console.log('Dismissed toast');
  });

  toast.present();
}

}

我在这里做错了什么?我已经在stackoverflow甚至从youtube或ionic文档中的教程中尝试了所有内容。但对我没有任何作用!

班邦

使用旧的离子型原生/ SQLite的版本4.xx的,而不是5.XX将最新的ionic-native / sqlite与Ionic 3一起使用时,我遇到了相同的问题。

使用npm卸载旧插件,或在package.json文件中对其进行更改

并且您需要更改以下行:

import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';

import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法读取未定义的属性“ split”

Ionic Cordova SQLite插件错误无法读取未定义的属性“ openDatabase”

无法读取未定义的属性(读取“updateLicence”)Ionic Angular

无法读取未定义的属性“目标”-Ionic Angular

Ionic InfiniteScroll:TypeError:无法读取未定义的属性“ 0”

AngularJS / Ionic TypeError:无法读取未定义的属性“ then”

Angular - Ionic 2 - 无法读取未定义的属性“订阅”

IONIC 4:无法读取未定义的属性“ get”

AngularJS-无法读取未定义的属性“ split”

Vue.js无法读取未定义的属性“ split”

Angular 7 + Ionic 4 构建失败“TypeError:无法读取未定义的属性(读取'种类')”

Ionic v4 Firebase:无法读取未定义的属性“电子邮件”

使用 AngularJS 和 Ionic 出现错误“TypeError:无法读取未定义的属性‘email’”

错误:无法读取 ionic 4 和 firebase 中未定义的属性“纬度”

TypeError:无法读取discord和nodejs中未定义的属性“ split”

TypeError:无法读取未定义的Ionic 3 / Angular 5的属性“ get”

需要与Ionic 3表单组配合,无法读取未定义的属性获取

Ionic 3和Angular 4-未捕获(承诺):TypeError:无法读取未定义的属性“ title”

ionic.bundle.js TypeError:无法读取未定义的属性“ add”

错误类型错误:在 IONIC 4 中保存联系人时无法读取未定义的属性“then”

Ionic / Chart.js-无法读取未定义的属性“ nativeElement”

无法读取Ionic 4(Angular 8)上未定义的属性“ subscribe”

ionic1 错误:TypeError:无法读取未定义的属性“emit”

NgZone / Angular2 / Ionic2 TypeError:无法读取未定义的属性“运行”

ReactJS 使用 Ionic Uncaught TypeError:无法从 axios 请求中读取未定义的属性“map”

Ionic / Angular JS-$ scope问题:无法读取未定义的属性“ length”

无法读取以下代码中未定义的属性“ split”

Uncaught TypeError:无法读取youtubedl.js上未定义的属性“ split”:4

错误TypeError:无法读取未定义的cordova-plugin-contact的属性“ split”