gpt4 book ai didi

javascript - 使用 Wcf 服务在 Angular Js 应用程序中添加总计

转载 作者:行者123 更新时间:2023-11-30 21:02:13 24 4
gpt4 key购买 nike

我是 Angular JS 的新手。我有一个 Wcf Rest 服务来从数据库中获取所有记录并且它正在工作,但我试图在页面底部添加总计,但我做不到。厌倦了显示 grand totla 它显示的是短信。我正在尝试添加 Clomun 的量..

这是我的脚本代码..

var app = angular.module("WebClientModule", [])

.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {

$scope.OperType = 1;
$scope.Account_Number = "";
$scope.Account_Holder_Name = "";
$scope.Amount = "";
$scope.Sort_Code = "";
$scope.Transcation_Type = "";
$scope.Date = "";

GetAllRecords();
//To Get All Records
function GetAllRecords() {
var promiseGet = myService.getAllStudent();
promiseGet.then(function (pl) { $scope.Users = pl.data },
function (errorPl) {
$log.error('Some Error in Getting Records.', errorPl);
});
}

//$scope.getTotal = function () {
// var total = 0;
// for (var i = 0; i < $scope.cart.Amount.length; i++) {
// var product = $scope.cart.Users[i];
// total += (user.Amount + user.Amount);
// }
// return total;
//}
}]);



app.service("myService", function ($http) {

this.getAllStudent = function () {
return $http.get("http://localhost:52098/HalifaxIISService.svc/GetCreateCurrentAccountDepositList");
}
})

这是我的 HTML 代码..

@{
Layout = null;
}

<!DOCTYPE html>

<html data-ng-app="WebClientModule">
<head>
<meta name="viewport" content="width=device-width" />
<title>TotalDeposit</title>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/RegistrationScript/DepositTotal.js"></script>

</head>
<body>
<table ng-init="items.total = {}" id="tblContainer" data-ng-controller="Web_Client_Controller">
<tr>
<td>
<table style="border: solid 2px Green; padding: 5px;">
<tr style="height: 30px; background-color: skyblue; color: maroon;">
<th></th>
<th>Account Number</th>
<th>Account Holder Name</th>

<th>Amount</th>
<th>Sort Code</th>
<th>Transcation Type</th>
<th>Date</th>

<th></th>
<th></th>
</tr>
<tbody data-ng-repeat="user in Users">
<tr>
<td></td>
<td><span>{{user.Account_Number}}</span></td>
<td><span>{{user.Account_Holder_Name}}</span></td>
<td><span>{{user.Amount}}</span></td>

<td><span>{{user.Sort_Code}}</span></td>

<td><span>{{user.Transcation_Type}}</span></td>
<td><span>{{user.Date}}</span></td>

</tr>
</tbody>
<td ng-init="Users.total.amount = items.total.amount + item.amount">{{user.amount}}</td>

</table>
</td>
</tr>

<tr>
<td>Total</td>

<td>{{items.total.amount}}</td>

</tr>

</table>
</body>
</html>

这是运行应用程序时的屏幕截图。 click here to see the reuslt

最佳答案

创建一个函数来获取总计,例如

    $scope.grandTotal= function(){
return $scope.users.reduce(function(a, b){
return a + b.amount;
},0);
}

然后在 html 中

<tr>
<td>Total</td>

<td>{{grandTotal()}}</td>

</tr>

Working demo

reference for array.reduce

关于javascript - 使用 Wcf 服务在 Angular Js 应用程序中添加总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47027441/

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