gpt4 book ai didi

ionic 的 SQLite 数据库

转载 作者:行者123 更新时间:2023-12-03 17:39:47 24 4
gpt4 key购买 nike

我在 ionic 框架中的 SQLiteDatabase 中执行 CRUD 操作时遇到问题。
这是我的主要“index.html”页面,我通过使用“replaceWith()”替换另一个 div 来显示我的 div,这是我最近学到的!

<meta charset="utf-8">
<meta name="viewport"
content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Still Learning</title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/jquery-1.11.3.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<script>
$(document).ready(function(){
$("#insertbtn").click(function(){
$(".toshow").replaceWith('<div class="toshow" ng-controller="MyController">\
<div class="list">\
<label class="item item-input">\
<input type="text" placeholder="Full Name" ng-model="fullname">\
</label>\
<label class="item item-input">\
<input type="text" placeholder="Address" ng-model="address">\
</label>\
<label class="item item-input">\
<input type="text" placeholder="Email" ng-model="email">\
</label>\
<label class="item item-input">\
<input type="number" placeholder="Age" ng-model="age">\
</label>\
<label class="item item-input">\
<input type="password" placeholder="Password" ng-model="password">\
</label>\
<label class="item item-input">\
<textarea placeholder="Details" ng-model="details"></textarea>\
</label>\
<br /><button class="button button-outline button-positive" ng-click="insert(fullname, address, email, age, password, details)">INSERT</button>\
</div><p>{{ statusMessage }}</p>\
</div>');
});

});
</script>

现在在这里,在这个被替换的 div 中,我添加了一些值并希望将其插入 SQLite 数据库!

这是我的 app.js 文件:
    var db=null;
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}

db = $cordovaSQLite.openDB("sample.db");
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS User(id INTEGER PRIMARY KEY AUTOINCREMENT, fullname TEXT, address TEXT,email TEXT, age INTEGER, password TEXT, details TEXT)');
});
})

.controller('MyController', function($scope, $cordovaSQLite) {
$scope.insert = function(fullname, address, email, age, password, details) {
$cordovaSQLite.execute(db, 'INSERT INTO User (fullname, address, email, age, password, details) VALUES (?,?,?,?,?,?)', [fullname, address, email, age, password, details])
.then(function(result) {
$scope.statusMessage = "Data saved successful, cheers!";
}, function(error) {
$scope.statusMessage = "Error on saving: " + error.message;
})
}
})

没有错误,但是我的数据没有被插入!!有人可以告诉我我的错误是什么吗?提前谢谢......

最佳答案

.run(function($ionicPlatform , **$cordovaSQLite**) 
{
//all the code remain same here
}

这里需要在 .run()中多加一个参数函数是 $cordovaSQLite
这会帮助你:)

关于 ionic 的 SQLite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32165528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com