![](/img/trans.png)
[英]Ionic Cordova $http POST data works well in browser but does not work in my android phone
[英]Ionic Cordova SQLite works well on browser but does not work persistent in Android device
我正在开发离子科尔多瓦混合应用程序。 当我使用浏览器进行测试时,应用程序运行良好。 但是我在我的真实设备中对其进行了测试,但它并不是非常持久。 这意味着SQLite有时效果很好,有时效果不好。 以下是我的代码:
app.js
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_channel(id interger primary key, chat_room text, last_text text, username text, chat_channel text unique)");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_content(id integer primary key, content text, channel text, chat_flag integer, username text, date timestamp)");
});
controller.js
var query = "SELECT * FROM chat_content WHERE channel=? ORDER BY date";
var promise = $cordovaSQLite.execute(db, query, [subscribeChannel]).then(function(result){
for(i=0; i<result.rows.length; i++){
$scope.messages.push(result.rows.item(i));
console.log(result.rows.item(i));
}
});
请尝试以下操作:
1.通过将它们放置在index.html文件的底部,最后加载ng-cordova-min.js或ng-cordova.js和cordova.js文件
2.在您的app.js文件中,数据库初始化应为第一行,即
var db = null;
应该是顶部的第一行。 仍然在您的app.js文件中,
db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000");
应该是平台就绪功能的第一行。 您的代码应在app.js文件中类似这样;
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_channel(id interger primary key, chat_room text, last_text text, username text, chat_channel text unique)");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_content(id integer primary key, content text, channel text, chat_flag integer, username text, date timestamp)");
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.