gpt4 book ai didi

javascript - cordovaSQLite 无法工作,错误 : undefined is not an object (evaluating 'n.transaction' )

转载 作者:行者123 更新时间:2023-12-03 08:00:01 25 4
gpt4 key购买 nike

这是我确定导致问题的代码部分:

angular.module('starter.controllers', []).controller('StudentsCtrl', function ($scope, $cordovaSQLite) {

var query = "SELECT id, student_id, username FROM students";
var users = [];

$cordovaSQLite.execute(db, query).then(function (data) {
$.each(data, function(i, item) {
users.push(item);
});
});

$scope.users = users;
});

我已经包含了 $cordovaSQLite 工作所需的文件。上面的代码位于 www/js/controllers.js 内部,作为默认 Ionic 选项卡式项目的一部分。 $cordovaSQLitewww/js/app.js 内部工作正常,在 www/js/controllers.js 的另一部分也工作正常,但上面的代码部分返回给我这个错误:

0     610246   error    Error: undefined is not an object (evaluating 'n.transaction')

更新: 看来 $cordovaSQLite 等于此函数中的 undefined,但我不太确定这是为什么正在发生。

最佳答案

您的代码在 Cordova deviceready 事件触发之前运行。您需要等待它才能使用任何设备功能,例如插件。在 Ionic 中,如果您在 Controller 中使用 $ionicPlatform,您可以执行以下操作:

$ionicPlatform.ready(function() {

作为包装需要等待的代码的一种方式。试试这个:

angular.module('starter.controllers', []).controller('StudentsCtrl,$ionicPlatform', function ($scope, $cordovaSQLite) {

$ionicPlatform.ready(function() {
var query = "SELECT id, student_id, username FROM students";
var users = [];

$cordovaSQLite.execute(db, query).then(function (data) {
$.each(data, function(i, item) {
users.push(item);
});
});

$scope.users = users;

});

});

关于javascript - cordovaSQLite 无法工作,错误 : undefined is not an object (evaluating 'n.transaction' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34630013/

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