Ionicフレームワークも使用してAndroidおよびIOS用のApache Cordovaアプリを開発しています。これには、ローカルストレージに小さなデータベースが必要であり、SQLiteを使用したくありません。私は多くのチュートリアルに従っていますが、実際にはこれは非常に簡単です-少なくともそう思われます-しかし、次のエラーがあります:
Uncaught TypeError: Cannot read property 'openDatabase' of undefined (11:52:54:666 | error, javascript)
at (anonymous function) (www/js/app.js:47:29)
at (anonymous function) (www/lib/ionic/js/ionic.bundle.js:53329:19)
at onPlatformReady (www/lib/ionic/js/ionic.bundle.js:2491:24)
at onWindowLoad (www/lib/ionic/js/ionic.bundle.js:2472:7)
このエラーの後、データベースは作成されません。つまり、機能しません。明らかに、私はインターネットでこれについて研究し、多くの可能な解決策を見つけました。これを説明できる最も近似した解決策は次のとおりです。
TypeError: 未定義のプロパティ 'openDatabase' を読み取れません
しかし、私はうまくいきません:(
最後のリンクから引用するには:
これは、いくつかの理由のいずれかで発生しています。
1. $cordovaSQLite メソッドを $ionicPlatform.ready() 関数でラップしていません。
2.Web ブラウザからこのネイティブ プラグインをテストしようとしています。
3.実際にはベース SQLite プラグインをプロジェクトにインストールしていません。
私の場合:
- $cordovaSQLite メソッドは $ionicPlatform.ready 関数内にあります。
- 物理的な Android デバイスを使用してテストしています。
- 次のソースからプロジェクトにプラグインをインストールしました。
https://github.com/brodysoft/Cordova-SQLitePlugin-2014.07.git
私が言ったように、私はこれについて多くのことを研究していますが、この状況を解決することはできません。
私のコード:
params.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
db = window.sqlitePlugin.openDatabase({name: "inspeccionesDB.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS table1 (id integer primary key autoincrement not null, company char(255) not null, cif char(20) not null, state char(20) not null, related_ids char(45) not null)");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS table2 (id integer primary key not null, code char(20) not null, firstname char(20) not null, surname char(100) not null, surname1 char(100) not null, nif char(20) not null, expired_passport_dt text not null, is_valid tinyint not null");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS table3 (id integer primary key not null, code char(20), address char(250), location char(100), provincia(250))");
});
});
アドバイスや可能な解決策があれば、絶対に感謝します。
みなさん、よろしくお願いします。