【发布时间】:2017-01-02 11:53:06
【问题描述】:
我使用 AngularJS 和使用 MySQL 数据库的 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'];
};
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 应用程序项目:
【问题讨论】:
-
你需要确保你的函数在对它们求和时返回一个 int 或 float。
-
@HRgiger:没有必要在所有正在使用的技术中添加粗体——这使得它更难阅读。只需确保 OP 的情况正确(例如 MySQL 而不是 MYSQL)。
-
@halfer 指出:)