AngularJS with RESTful MySQL



我使用 MySQL 数据库将 AngularJS 与 RESTful WebService 一起使用。我从数据库获取数据以查看页面。但我的问题是:我不能用函数求和。

问题代码:

$scope.currentAssetsSum = function () {
//return parseFloat($scope.currentAssetsData.cash_hand) + parseFloat($scope.currentAssetsData.bank_account);
return $scope.currentAssetsData['cash_hand'] + $scope.currentAssetsData['bank_account'];
};

JAR 列表:


MySQL 数据库:

    CREATE TABLE  current_assets (
id int(10) unsigned NOT NULL auto_increment, 
cash_hand double NOT NULL, 
bank_account double NOT NULL, 
PRIMARY KEY  (id));

NetBeans Web 应用程序项目:

https://github.com/hellodewdrop/AngularJS_RESTful_MySQL

你之前是否将变量$scope.currentAssetsData声明为对象?然后,如果您的数据不是浮点数,则可以进行转换。

像这样:

var app = angular.module("myApp", []);
        app.controller("myCtrl", function ($scope, $http) {
           $scope.currentAssetsData = {};
            //Current Assets Table
            $http({
                method: "GET",
                url: "http://localhost:8084/Final_Balance/rest/currentAssets"
            }).then(function mySucces(response) {
                $scope.currentAssetsData = response.data;
                console.log($scope.currentAssetsData.length);
            }, function myError(response) {
                console.log("Data can't be loaded..");
            });
            //Calculation from Table
            $scope.currentAssetsSum = function () {
                return parseFloat($scope.currentAssetsData.cash_hand) + parseFloat($scope.currentAssetsData.bank_account);
            };
        });

最新更新