离子应用程序在Android设备上无法正常工作

时间:2017-03-23 08:58:01

标签: android sqlite ionic-framework

我是离子1的新手。我一直在制作一个使用过SQLite的应用程序。该应用程序在浏览器上运行完美但部分在设备上运行。有一个按钮不起作用。包含此按钮的代码如下所示。按钮功能名称是充电。这是我的代码:

angular.module('app.cartCtrl', ['ngCordova'])

    .controller('cartCtrl', ['$scope', '$stateParams', '$state', '$cordovaSQLite', '$ionicHistory', '$ionicPopup',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller

        $stateParams.parameterName
        function ($scope, $stateParams, $state, $cordovaSQLite, $ionicHistory, $ionicPopup) {





            $scope.items = [];
            $scope.grandTotal = 0;
            $scope.receiptnumber = 0;
            $scope.receiptnumber = $scope.receiptnumber + 1;
            $scope.items = [];
            $scope.item = {};
            $scope.grandTotal = null;






            var query2 = "SELECT * FROM items WHERE quantity!='' ";
            console.log(query2);
            $cordovaSQLite.execute(db, query2, []).then(function (res) {

                if (res.rows.length > 0) {

                    for (var i = 0; i < res.rows.length; i++) {

                        $scope.items.push({

                            itemname: res.rows.item(i).itemname,
                            price: res.rows.item(i).price,
                            quantity: res.rows.item(i).quantity,


                        });


                        $scope.items = $scope.items;

                    }
                } else {
                    console.log("No results found");
                }
            }, function (err) {
                console.error("error=>" + err);
            });




            $ionicHistory.clearCache();
            $ionicHistory.clearHistory();




            var query = "SELECT SUM(total) FROM items";


            $cordovaSQLite.execute(db, query, []).then(function (res) {


                $scope.grandTotal = res.rows[0]['SUM(total)'];

                //$scope.grandtotal = parseFloat(res.rows[0]['SUM(total)']);
                // console.log("Grand total is" + res.rows[0]['SUM(total)']);

            }, function (err) {
                console.error("error=>" + err);
            });












            $scope.myGoBack = function () {

                $state.go("menu.sales");


            };



            $scope.charge = function () {

                $state.go('transactionsuccess');


            }



        }]) 

我怀疑下面的代码。它可以在设备或模拟器上运行:

res.rows[0]['SUM(total)']

1 个答案:

答案 0 :(得分:0)

尝试使用此更新的查询并检查发布日志的内容

var query2 = "SELECT * FROM items WHERE quantity!='' ";
console.log(query2);
$cordovaSQLite.execute(db, query2, [5]).then(function (res) {
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
$scope.items.push({
itemname: res.rows.item(i).itemname,
price: res.rows.item(i).price,
quantity: res.rows.item(i).quantity,
});
$scope.items = $scope.items;
}
} else {
console.log("No results found");
}
}, function (err) {
console.error("error=>" + err);
});
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
var query = "SELECT SUM(total) total FROM items";
$cordovaSQLite.execute(db, query, []).then(function (res) {
console.log('Result: ', res);
$scope.grandTotal = res.rows[0].total;
//$scope.grandtotal = parseFloat(res.rows[0]['SUM(total)']);
// console.log("Grand total is" + res.rows[0]['SUM(total)']);
}, function (err) {
console.error("error=>" + err);
});